当前位置: 首页>>代码示例>>Java>>正文


Java FindOneAndUpdateOptions.returnDocument方法代码示例

本文整理汇总了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));
}
 
开发者ID:OkraScheduler,项目名称:OkraSync,代码行数:23,代码来源:OkraSyncImpl.java

示例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);
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:25,代码来源:UpdateTest.java

示例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;
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:24,代码来源:MongoClientImpl.java

示例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));
}
 
开发者ID:OkraScheduler,项目名称:OkraSync,代码行数:31,代码来源:OkraSyncImpl.java

示例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));
}
 
开发者ID:OkraScheduler,项目名称:OkraSync,代码行数:31,代码来源:OkraSyncImpl.java

示例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;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:12,代码来源:SmofOpOptionsImpl.java

示例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;
	}
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:47,代码来源:MongoCollectionFindAndModify.java


注:本文中的com.mongodb.client.model.FindOneAndUpdateOptions.returnDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。