【转】Java操作MongoDB(3)
public void testOthers() { DBObject user = new BasicDBObject(); user.put("name", "hoojo"); user.put("age", 24); //JSON 对象转换 print("serialize: " + JSON.serialize(user)); //反序列化 print
public void testOthers() { DBObject user = new BasicDBObject(); user.put("name", "hoojo"); user.put("age", 24); //JSON 对象转换 print("serialize: " + JSON.serialize(user)); //反序列化 print("parse: " + JSON.parse("{ \"name\" : \"hoojo\" , \"age\" : 24}")); print("判断temp Collection是否存在: " + db.collectionExists("temp")); //如果不存在就创建 if (!db.collectionExists("temp")) { DBObject options = new BasicDBObject(); options.put("size", 20); options.put("capped", 20); options.put("max", 20); print(db.createCollection("account", options)); } //设置db为只读 db.setReadOnly(true); //只读不能写入数据 db.getCollection("test").save(user); }
转自:http://www.cnblogs.com/hoojo/archive/2011/06/02/2068665.html
收藏文章
精彩图集
精彩文章