Find exampleįind document where “name=mkyong”, and display it with DBCursorīasicDBObject searchQuery = new BasicDBObject() ĭBCursor cursor = table.find(searchQuery) Refer to this Java MongoDB update example. NewDocument.put("name", "mkyong-updated") īasicDBObject updateObj = new BasicDBObject() Update exampleīasicDBObject query = new BasicDBObject() īasicDBObject newDocument = new BasicDBObject() Refer to this Java MongoDB insert example. Save a document (data) into a collection (table) named “user”.ĭBCollection table = db.getCollection("user") īasicDBObject document = new BasicDBObject() MongoClient mongoClient = new MongoClient() ĭB db = mongoClient.getDB("database name") īoolean auth = db.authenticate("username", "password".toCharArray()) If MongoDB in secure mode, authentication is required. MongoClient mongo = new MongoClient( "localhost", 27017 ) Mongo mongo = new Mongo("localhost", 27017) For MongoDB version >= 2.10.0, uses MongoClient.
0 Comments
Leave a Reply. |