Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2014
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package com.mongoproject;
  2.  
  3. import com.mongodb.*;
  4.  
  5. import java.net.UnknownHostException;
  6.  
  7. // Created by Sasanka on 27-Aug-2014.
  8. public class MongoBinary2 {
  9.  
  10. public static void main(String arg[]) throws UnknownHostException {
  11.  
  12. MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
  13. DB db = mongoClient.getDB("chat");
  14. DBCollection coll = db.getCollection("test");
  15. byte[] uuid = "78960c69-0104-44d4-bcfc-ca05ad7089ff".getBytes();
  16. System.out.println(uuid);
  17. DBCursor cursor =null;
  18. coll.save(new BasicDBObject("_id", uuid));
  19.  
  20.  
  21. byte[] findUuid = "78960c69-0104-44d4-bcfc-ca05ad7089ff".getBytes();
  22. System.out.println(findUuid);
  23.  
  24. BasicDBObject query = new BasicDBObject("_id", findUuid);
  25.  
  26. cursor = coll.find(query);
  27. while(cursor.hasNext()){
  28.  
  29. BasicDBObject dbObject = (BasicDBObject)cursor.next();
  30. byte[] retrieved = (byte[])dbObject.get("_id");
  31. System.out.println(new String(retrieved));
  32. }
  33.  
  34. }
  35.  
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement