Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mongoproject;
- import com.mongodb.*;
- import java.net.UnknownHostException;
- // Created by Sasanka on 27-Aug-2014.
- public class MongoBinary2 {
- public static void main(String arg[]) throws UnknownHostException {
- MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
- DB db = mongoClient.getDB("chat");
- DBCollection coll = db.getCollection("test");
- byte[] uuid = "78960c69-0104-44d4-bcfc-ca05ad7089ff".getBytes();
- System.out.println(uuid);
- DBCursor cursor =null;
- coll.save(new BasicDBObject("_id", uuid));
- byte[] findUuid = "78960c69-0104-44d4-bcfc-ca05ad7089ff".getBytes();
- System.out.println(findUuid);
- BasicDBObject query = new BasicDBObject("_id", findUuid);
- cursor = coll.find(query);
- while(cursor.hasNext()){
- BasicDBObject dbObject = (BasicDBObject)cursor.next();
- byte[] retrieved = (byte[])dbObject.get("_id");
- System.out.println(new String(retrieved));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement