本文整理汇总了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);
}