本文整理匯總了Java中com.mongodb.client.MongoCollection.findOneAndUpdate方法的典型用法代碼示例。如果您正苦於以下問題:Java MongoCollection.findOneAndUpdate方法的具體用法?Java MongoCollection.findOneAndUpdate怎麽用?Java MongoCollection.findOneAndUpdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mongodb.client.MongoCollection
的用法示例。
在下文中一共展示了MongoCollection.findOneAndUpdate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updatePojoTest
import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
@Test
public void updatePojoTest() {
Bson update = combine(set("user", "Jim"),
set("action", Action.DELETE),
// unfortunately at this point we need to provide a non generic class, so the codec is able to determine all types
// remember: type erasure makes it impossible to retrieve type argument values at runtime
// @todo provide a mechanism to generate non-generic class on the fly. Is that even possible ?
// set("listOfPolymorphicTypes", buildNonGenericClassOnTheFly(Arrays.asList(new A(123), new B(456f)), List.class, Type.class),
set("listOfPolymorphicTypes", new PolymorphicTypeList(Arrays.asList(new A(123), new B(456f)))),
currentDate("creationDate"),
currentTimestamp("_id"));
FindOneAndUpdateOptions findOptions = new FindOneAndUpdateOptions();
findOptions.upsert(true);
findOptions.returnDocument(ReturnDocument.AFTER);
MongoCollection<Pojo> pojoMongoCollection = mongoClient.getDatabase("test").getCollection("documents").withDocumentClass(Pojo.class);
Pojo pojo = pojoMongoCollection.findOneAndUpdate(Filters.and(Filters.lt(DBCollection.ID_FIELD_NAME, 0),
Filters.gt(DBCollection.ID_FIELD_NAME, 0)), update, findOptions);
assertNotNull(pojo.id);
}