com.mongodb.client.model.Updates.setOnInsert()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中com.mongodb.client.model.Updates.setOnInsert()方法的一些代码示例,展示了Updates.setOnInsert()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Updates.setOnInsert()方法的具体详情如下:
包路径:com.mongodb.client.model.Updates
类名称:Updates
方法名:setOnInsert

Updates.setOnInsert介绍

[英]Creates an update that sets the value of the field with the given name to the given value, but only if the update is an upsert that results in an insert of a document.
[中]创建更新,将具有给定名称的字段的值设置为给定值,但仅当更新是导致插入文档的upsert时。

代码示例

代码示例来源:origin: creactiviti/piper

@Override
public void set(String aCounterName, long aValue) {
 collection
   .findOneAndUpdate(
     eq("_id", aCounterName),
     combine(
       Updates.set(DSL.VALUE, aValue),
       setOnInsert("_id", aCounterName),
       setOnInsert(DSL.CREATE_TIME, new Date())
     ),
     new FindOneAndUpdateOptions()
       .upsert(true)
   );
}

代码示例来源:origin: opencb/opencga

bsons.add(setOnInsert(StageDocumentToVariantConverter.END_FIELD, id.get(StageDocumentToVariantConverter.END_FIELD)));
bsons.add(setOnInsert(StageDocumentToVariantConverter.REF_FIELD, id.get(StageDocumentToVariantConverter.REF_FIELD)));
bsons.add(setOnInsert(StageDocumentToVariantConverter.ALT_FIELD, id.get(StageDocumentToVariantConverter.ALT_FIELD)));
updates.add(combine(bsons));

代码示例来源:origin: opencb/opencga

Object value = entry.getValue();
if (value instanceof List) {
  updates.add(setOnInsert(entry.getKey(), new BsonArray(((List) value))));
} else {
  updates.add(setOnInsert(entry.getKey(), value));

代码示例来源:origin: atlanmod/NeoEMF

@Override
public boolean metaClassFor(Id id, ClassBean metaClass) {
  checkNotNull(id, "id");
  checkNotNull(metaClass, "metaClass");
  final String ownerId = idConverter.convert(id);
  final ClassDocument newMetaClass = ClassDocument.fromBean(metaClass);
  final Bson filter = eq(ModelDocument.F_ID, ownerId);
  final Bson existsFilter = and(filter, exists(ModelDocument.F_METACLASS));
  final boolean notExists = documents.countDocuments(existsFilter, new CountOptions().limit(1)) == 0;
  if (notExists) {
    final Bson update = combine(
        setOnInsert(concat(ModelDocument.F_METACLASS, ClassDocument.F_NAME), newMetaClass.getName()),
        setOnInsert(concat(ModelDocument.F_METACLASS, ClassDocument.F_URI), newMetaClass.getUri())
    );
    documents.updateOne(filter, update, new UpdateOptions().upsert(true));
  }
  return notExists;
}

相关文章