Java MongoDB - Commands

Queries only the "productID" and "@type" fields from all the collection documents:

BasicDBObject fields = new BasicDBObject();
query.put("productID", 1);
query.put("@type", 2);

BasicDBObject allQuery = new BasicDBObject();

DBCursor cursor = mongoDatasource.getMongoDatasource().find(allQuery, fields);

while(cursor.hasNext()) {
DBObject document =;

{ "_id" : { "$oid" : "56c6c9e0612eb61e88166894"} , "@type" : "Product" , "productID" : "1"}

Adding a new node to an exisitng array

BasicDBObject query = new BasicDBObject().append("productID", String.valueOf(productId));
DBObject listItem = new BasicDBObject("offers.offers", newValue);
BasicDBObject update = new BasicDBObject().append("$push", listItem);
mongoDatasource.getMongoDatasource().update(query, update, false, true);


Popular posts from this blog

spring @async causing BeanCurrentlyInCreationException

Oracle - duplicate fields in RECORD,TABLE or argument list are not permitted