【济南中心】NoSQL非关系型数据库——MongoDB(四)
分片(sharding):
Mongo mongo = new Mongo("localhost",27017); DB db = mongo.getDB("test"); DBCollection collection = db.getCollection("customer"); DBCursor dbCursor = collection.find(); System.out.println(collection.getCount()); while(dbCursor.hasNext()){ System.out.println(dbCursor.next()); } mongo.close(); |
Mongomongo= newMongo("localhost",27017); DB db= mongo.getDB("test"); DBCollection collection = db.getCollection("customer"); BasicDBObject o = newBasicDBObject("_id", new ObjectId("5199ee647d5fc789bc760c07")); collection.remove(o); mongo.close(); |
Mongomongo= newMongo("localhost",27017); DB db= mongo.getDB("test"); DBCollection collection = db.getCollection("customer"); DBObject c = newBasicDBObject(); c.put("name", “jack"); c.put("age", 24); collection.insert(c); mongo.close(); |
Mongomongo= newMongo("localhost",27017); DB db= mongo.getDB("test"); DBCollection collection = db.getCollection("customer"); BasicDBObject query = new BasicDBObject("_id",new ObjectId("519e2e393296cf3baccdb10c")); BasicDBObject object = (BasicDBObject) collection.findOne(query); object.put("name", “wangwu"); int n = collection.update(query, object).getN(); System.out.println(n); mongo.close(); |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |