Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package com.mongoproject;
  2.  
  3. import com.mongodb.*;
  4.  
  5. import javax.management.Query;
  6. import java.net.UnknownHostException;
  7. import java.nio.ByteBuffer;
  8. import java.nio.charset.Charset;
  9. import java.util.Arrays;
  10. import java.util.HashMap;
  11. import java.util.Map;
  12. import java.util.UUID;
  13. import com.mongoproject.ByteArrayWrapper;
  14. import org.bson.types.ObjectId;
  15.  
  16. // Created by Sasanka on 27-Aug-2014.
  17. public class MongoBinary2 {
  18.  
  19. public static void main(String arg[]) throws UnknownHostException {
  20.  
  21. MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
  22. DB db = mongoClient.getDB("chat");
  23. DBCollection coll = db.getCollection("test");
  24. byte[] uuid = "uuid".getBytes();
  25.  
  26. DBCursor cursor =null;
  27. coll.save(new BasicDBObject("_id", uuid));
  28.  
  29.  
  30. byte[] findUuid = "uuid".getBytes();
  31.  
  32. BasicDBObject query = new BasicDBObject("_id", findUuid);
  33.  
  34. cursor = coll.find(query);
  35. while(cursor.hasNext()){
  36.  
  37. BasicDBObject dbObject = (BasicDBObject)cursor.next();
  38. byte[] retrieved = (byte[])dbObject.get("_id");
  39. System.out.println(new String(retrieved));
  40. }
  41.  
  42. }
  43.  
  44.  
  45. }
  46.  
  47.  
  48. Output : uuid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement