Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mongoproject;
- import com.mongodb.*;
- import javax.management.Query;
- import java.net.UnknownHostException;
- import java.nio.ByteBuffer;
- import java.nio.charset.Charset;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.UUID;
- import com.mongoproject.ByteArrayWrapper;
- import org.bson.types.ObjectId;
- // 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 = "uuid".getBytes();
- DBCursor cursor =null;
- coll.save(new BasicDBObject("_id", uuid));
- byte[] findUuid = "uuid".getBytes();
- 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));
- }
- }
- }
- Output : uuid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement