List of usage examples for com.mongodb DBCollection update
public WriteResult update(final DBObject query, final DBObject update, final boolean upsert, final boolean multi, final WriteConcern aWriteConcern)
From source file:org.teiid.translator.mongodb.MongoDBUpdateExecution.java
License:Open Source License
private void updateReferenceTables(DBCollection collection, MongoDocument mongoDoc, DBObject match, AggregationOptions options) throws TranslatorException { DBObject m = new BasicDBObject("$match", match); //$NON-NLS-1$ Cursor output = collection.aggregate(Arrays.asList(m), options); while (output.hasNext()) { DBObject row = output.next();//from w w w .j a va2 s . com if (row != null) { for (MergeDetails ref : mongoDoc.getEmbeddedIntoReferences()) { DBCollection parent = getCollection(ref.getParentTable()); //DBObject parentmatch = new BasicDBObject(ref.getReferenceName()+".$id", row.get("_id")); //$NON-NLS-1$ //$NON-NLS-2$ DBObject parentmatch = buildParentMatch(row, ref); row.removeField("_id"); //$NON-NLS-1$ parent.update(parentmatch, new BasicDBObject("$set", new BasicDBObject(ref.getName(), row)), //$NON-NLS-1$ false, true, WriteConcern.ACKNOWLEDGED); // see if there are nested references Table parentTable = this.metadata.getTable(mongoDoc.getTable().getParent().getName(), ref.getParentTable()); MongoDocument parentMongoDocument = new MongoDocument(parentTable, this.metadata); if (parentMongoDocument.isEmbeddable()) { updateReferenceTables(parent, parentMongoDocument, parentmatch, options); } } } } }
From source file:pubsub.broker.model.Publisher.java
@Override public void save() { DBCollection packageColl = db.getCollection(DBConstants.PUBLISHER_COLLECTION); BasicDBObject query = new BasicDBObject(); query.put(DBConstants.PUBLISHER_EMAIL, this.email); packageColl.update(query, this, true, false, WriteConcern.FSYNCED); }
From source file:rtpmt.models.Config.java
public void save() { DBCollection packageColl = db.getCollection(DBConstants.CONFIG_COLLECTION); BasicDBObject query = new BasicDBObject(); query.put(DBConstants.SENSOR_ID, this.get(DBConstants.SENSOR_ID)); query.put(DBConstants.TRUCK_ID, this.get(DBConstants.TRUCK_ID)); query.put(DBConstants.PACKAGE_ID, this.get(DBConstants.PACKAGE_ID)); //query.put(DBConstants.TIMESTAMP, this.get(DBConstants.TIMESTAMP)); packageColl.update(query, this, true, false, WriteConcern.FSYNCED); }