0

As I required to import the collection of mongodb from a bson document. How do I achieve that? and I'm using Java. Is there any API for this? Guide me through this.

Thanks in advance

Varun Kumar
  • 1,015
  • 2
  • 9
  • 17
  • 3
    This question is a little unclear - what do you mean you have a BSON document? Do you mean a file on the file system, a Java class, or something else? Some more details of what you've tried and what you're trying to do would help, the answer from @jmen7070 below is the normal way to read from a MongoDB database using Java, so if this isn't what you want, we need more details. – Trisha Apr 29 '14 at 10:49

1 Answers1

0

Try code;

DB db = m.getDB(dbname);
DBCollection dbCollection = db.getCollection(collectionName);
DBCursor cursor = dbCollection.find();
while (cursor.hasNext()){
         System.out.println(cursor.next());
}
jmen7070
  • 606
  • 5
  • 9
  • I guess you didn't get me? My requirement is that if I have a bson document for a db and I want convert it into a DBObject so far I could process the database elements through my code. Please help me out for this. – Varun Kumar Apr 29 '14 at 10:37
  • Do you want to insert your bson in database with Java Driver? Can you give example of your bson? – jmen7070 Apr 29 '14 at 11:13