List of usage examples for com.mongodb.client.result UpdateResult acknowledged
public static UpdateResult acknowledged(final long matchedCount, @Nullable final Long modifiedCount, @Nullable final BsonValue upsertedId)
From source file:org.mongojack.JacksonMongoCollection.java
License:Apache License
/** * Saves an object to this collection (does insert or update based on the * object _id)./* w w w.j a va 2 s .c o m*/ * * @param object * the <code>DBObject</code> to save * @param concern * the write concern * @return The UpdateResult result * @throws MongoWriteException * If the write failed due some other failure specific to the delete command * @throws MongoWriteConcernException * If the write failed due being unable to fulfill the write concern * @throws MongoException * If an error occurred */ public UpdateResult save(T object, WriteConcern concern) throws MongoWriteException, MongoWriteConcernException, MongoException { Document dbObject = convertToDocument(object); Object _id = dbObject.get("_id"); if (_id == null) { this.insert(object, concern); return UpdateResult.acknowledged(0, 1L, new BsonObjectId((ObjectId) convertToDocument(object).get("_id"))); } else { return this.replaceOne(new Document("_id", _id), object, true, concern); } }