本文整理汇总了Java中com.mongodb.client.model.FindOneAndUpdateOptions.returnDocument方法的典型用法代码示例。如果您正苦于以下问题:Java FindOneAndUpdateOptions.returnDocument方法的具体用法?Java FindOneAndUpdateOptions.returnDocument怎么用?Java FindOneAndUpdateOptions.returnDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.client.model.FindOneAndUpdateOptions
的用法示例。
在下文中一共展示了FindOneAndUpdateOptions.returnDocument方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: peek
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入方法依赖的package包/类
@Override
public Optional<T> peek() {
final Bson peekQuery = QueryUtil.generatePeekQuery(defaultHeartbeatExpirationMillis);
final Document update = new Document();
update.put("heartbeat", new Date());
update.put("status", OkraStatus.PROCESSING.name());
final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.returnDocument(ReturnDocument.AFTER);
final Document document = client
.getDatabase(getDatabase())
.getCollection(getCollection())
.findOneAndUpdate(peekQuery, new Document("$set", update), options);
if (document == null) {
return Optional.empty();
}
return Optional.ofNullable(serializer.fromDocument(scheduleItemClass, document));
}
示例2: updatePojoTest
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入方法依赖的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);
}
示例3: findOneAndUpdateWithOptions
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入方法依赖的package包/类
@Override
public io.vertx.ext.mongo.MongoClient findOneAndUpdateWithOptions(String collection, JsonObject query, JsonObject update, FindOptions findOptions, UpdateOptions updateOptions, Handler<AsyncResult<JsonObject>> resultHandler) {
requireNonNull(collection, "collection cannot be null");
requireNonNull(query, "query cannot be null");
requireNonNull(update, "update cannot be null");
requireNonNull(findOptions, "find options cannot be null");
requireNonNull(updateOptions, "update options cannot be null");
requireNonNull(resultHandler, "resultHandler cannot be null");
JsonObject encodedQuery = encodeKeyWhenUseObjectId(query);
Bson bquery = wrap(encodedQuery);
Bson bupdate = wrap(update);
FindOneAndUpdateOptions foauOptions = new FindOneAndUpdateOptions();
foauOptions.sort(wrap(findOptions.getSort()));
foauOptions.projection(wrap(findOptions.getFields()));
foauOptions.upsert(updateOptions.isUpsert());
foauOptions.returnDocument(updateOptions.isReturningNewDocument() ? ReturnDocument.AFTER : ReturnDocument.BEFORE);
MongoCollection<JsonObject> coll = getCollection(collection);
coll.findOneAndUpdate(bquery, bupdate, foauOptions, wrapCallback(resultHandler));
return this;
}
示例4: reschedule
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入方法依赖的package包/类
@Override
public Optional<T> reschedule(final T item) {
validateReschedule(item);
final Document query = new Document();
query.put("_id", new ObjectId(item.getId()));
query.put("heartbeat", DateUtil.toDate(item.getHeartbeat()));
final Document setDoc = new Document();
setDoc.put("heartbeat", null);
setDoc.put("runDate", DateUtil.toDate(item.getRunDate()));
setDoc.put("status", OkraStatus.PENDING.name());
final Document update = new Document();
update.put("$set", setDoc);
final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.returnDocument(ReturnDocument.AFTER);
final Document document = client
.getDatabase(getDatabase())
.getCollection(getCollection())
.findOneAndUpdate(query, update, options);
if (document == null) {
return Optional.empty();
}
return Optional.ofNullable(serializer.fromDocument(scheduleItemClass, document));
}
示例5: heartbeatAndUpdateCustomAttrs
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入方法依赖的package包/类
@Override
public Optional<T> heartbeatAndUpdateCustomAttrs(final T item, final Map<String, Object> attrs) {
validateHeartbeat(item);
final Document query = new Document();
query.put("_id", new ObjectId(item.getId()));
query.put("status", OkraStatus.PROCESSING.name());
query.put("heartbeat", DateUtil.toDate(item.getHeartbeat()));
final Document update = new Document();
update.put("$set", new Document("heartbeat", new Date()));
if (attrs != null && !attrs.isEmpty()) {
attrs.forEach((key, value) -> update.append("$set", new Document(key, value)));
}
final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.returnDocument(ReturnDocument.AFTER);
final Document result = client
.getDatabase(getDatabase())
.getCollection(getCollection())
.findOneAndUpdate(query, update, options);
if (result == null) {
return Optional.empty();
}
return Optional.ofNullable(serializer.fromDocument(scheduleItemClass, result));
}
示例6: toFindOneAndUpdateOptions
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入方法依赖的package包/类
@Override
public FindOneAndUpdateOptions toFindOneAndUpdateOptions() {
final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.bypassDocumentValidation(!validateDocuments);
setMaxTime(options);
setProjection(options);
options.returnDocument(ret);
setSort(options);
options.upsert(upsert);
return options;
}
示例7: execute
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入方法依赖的package包/类
@SuppressWarnings( "rawtypes" )
public cfData execute(cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
MongoDatabase db = getMongoDatabase( _session, argStruct );
String collection = getNamedStringParam(argStruct, "collection", null);
if ( collection == null )
throwException(_session, "please specify a collection");
cfData update = getNamedParam(argStruct, "update", null );
if ( update == null )
throwException(_session, "please specify update");
cfData query = getNamedParam(argStruct, "query", null );
if ( query == null )
throwException(_session, "please specify query to update");
try{
MongoCollection<Document> col = db.getCollection(collection);
FindOneAndUpdateOptions findOneAndUpdateOptions = new FindOneAndUpdateOptions();
if ( getNamedParam(argStruct, "fields", null ) != null )
findOneAndUpdateOptions.projection( getDocument( getNamedParam(argStruct, "fields", null ) ) );
if ( getNamedParam(argStruct, "sort", null ) != null )
findOneAndUpdateOptions.sort( getDocument( getNamedParam(argStruct, "sort", null ) ) );
findOneAndUpdateOptions.upsert( getNamedBooleanParam(argStruct, "upsert", false ) );
if ( getNamedBooleanParam(argStruct, "returnnew", false ) )
findOneAndUpdateOptions.returnDocument( ReturnDocument.AFTER );
Document qry = getDocument(query);
long start = System.currentTimeMillis();
Document result = col.findOneAndUpdate( qry, getDocument(update), findOneAndUpdateOptions );
_session.getDebugRecorder().execMongo(col, "findandmodify", qry, System.currentTimeMillis()-start);
return tagUtils.convertToCfData( (Map)result );
} catch (MongoException me){
throwException(_session, me.getMessage());
return null;
}
}