本文整理了Java中com.mongodb.client.model.Updates.set()
方法的一些代码示例,展示了Updates.set()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Updates.set()
方法的具体详情如下:
包路径:com.mongodb.client.model.Updates
类名称:Updates
方法名:set
[英]Creates an update that sets the value of the field with the given name to the given value.
[中]创建一个更新,将具有给定名称的字段的值设置为给定值。
代码示例来源:origin: Graylog2/graylog2-server
final UpdateResult result = collection.updateOne(eq(FIELD_ALERT_CONDITIONS_ID, alertConditionId), set(ALERT_CONDITIONS_PARAMETERS_PREFIX + field, intValue));
代码示例来源:origin: pippo-java/pippo
@Override
public void save(SessionData sessionData) {
String sessionId = sessionData.getId();
this.sessions.updateOne(
eq(SESSION_ID, sessionId),
combine(
set(SESSION_ID, sessionId),
set(SESSION_TTL, new Date()),
set(SESSION_DATA, transcoder.encode(sessionData))),
new UpdateOptions().upsert(true));
}
代码示例来源:origin: T-baby/MongoDB-Plugin
public MongoQuery modify(String key, Object value) {
if (MongoDocumentKit.conversionValidation(value)) {
data.add(Updates.set(key, MongoDocumentKit.toDocument(value)));
} else {
data.add(Updates.set(key, value));
}
return this;
}
代码示例来源:origin: com.cybermkd/MongodbPlugin
public MongoQuery modify(String key, Object value) {
if (MongoDocumentKit.conversionValidation(value)) {
data.add(Updates.set(key, MongoDocumentKit.toDocument(value)));
} else {
data.add(Updates.set(key, value));
}
return this;
}
代码示例来源:origin: protegeproject/webprotege
public static Bson updateModified(UserId userId, long timestamp) {
return Updates.combine(
Updates.set(MODIFIED_AT, TimestampSerializer.toIsoDateTime(timestamp)),
Updates.set(MODIFIED_BY, userId.getUserName())
);
}
代码示例来源:origin: epam/DLab
/**
* Write the status of user key to Mongo database.
*
* @param user user name
* @param status the status of user key.
*/
public void updateKey(String user, String status) {
updateOne(USER_KEYS, eq(ID, user), set(STATUS, status));
}
代码示例来源:origin: epam/DLab
/**
* Updates the status of EDGE node.
*
* @param user user name
* @param status status of EDGE node
*/
public void updateEdgeStatus(String user, String status) {
updateOne(USER_EDGE,
eq(ID, user),
Updates.set(EDGE_STATUS, status));
}
代码示例来源:origin: epam/DLab
/**
* Updates the requirement for reuploading key for all user's corresponding exploratories in Mongo database.
*
* @param user user name.
* @param reuploadKeyRequired true/false.
* @param exploratoryStatuses statuses of exploratory.
*/
public void updateReuploadKeyForExploratories(String user, boolean reuploadKeyRequired,
UserInstanceStatus... exploratoryStatuses) {
updateMany(USER_INSTANCES, exploratoryStatusCondition(user, exploratoryStatuses),
set(REUPLOAD_KEY_REQUIRED, reuploadKeyRequired));
}
代码示例来源:origin: de.bwaldvogel/mongo-java-server-test-common
private void insertUpdateInBulkNoMatch(boolean ordered) {
collection.insertOne(json("foo: 'bar'"));
List<WriteModel<Document>> ops = new ArrayList<>();
ops.add(new UpdateOneModel<Document>(ne("foo", "bar"), set("field", "y")));
BulkWriteResult result = collection.bulkWrite(ops, new BulkWriteOptions().ordered(ordered));
assertThat(result.getInsertedCount()).isEqualTo(0);
assertThat(result.getDeletedCount()).isEqualTo(0);
assertThat(result.getModifiedCount()).isEqualTo(0);
assertThat(result.getMatchedCount()).isEqualTo(0);
}
代码示例来源:origin: epam/DLab
/**
* Updates the status for all user's corresponding exploratories in Mongo database.
*
* @param newExploratoryStatus new status for exploratories.
* @param user user name.
* @param oldExploratoryStatuses old statuses of exploratories.
*/
public void updateStatusForExploratories(UserInstanceStatus newExploratoryStatus, String user,
UserInstanceStatus... oldExploratoryStatuses) {
updateMany(USER_INSTANCES, exploratoryStatusCondition(user, oldExploratoryStatuses),
set(STATUS, newExploratoryStatus.toString()));
}
代码示例来源:origin: lukas-krecan/ShedLock
@Override
public void unlock() {
// Set lockUtil to now or lockAtLeastUntil whichever is later
getCollection().findOneAndUpdate(
eq(ID, lockConfiguration.getName()),
combine(set(LOCK_UNTIL, Date.from(lockConfiguration.getUnlockTime())))
);
}
}
代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-mongodb
@Override
public void mark(String digest) {
Document dbFile = filesColl.findOneAndUpdate(Filters.eq(METADATA_PROPERTY_FILENAME, digest),
Updates.set(String.format("%s.%s", METADATA_PROPERTY_METADATA, msKey), TRUE),
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER));
if (dbFile != null) {
status.numBinaries += 1;
status.sizeBinaries += dbFile.getLong(METADATA_PROPERTY_LENGTH);
}
}
代码示例来源:origin: de.bwaldvogel/mongo-java-server-test-common
@Test
public void testUpsertWithoutId() {
UpdateResult result = collection.updateOne(eq("a", 1), set("a", 2), new UpdateOptions().upsert(true));
assertThat(result.getModifiedCount()).isEqualTo(0);
assertThat(result.getUpsertedId()).isNotNull();
assertThat(collection.find().first().get("_id")).isInstanceOf(ObjectId.class);
assertThat(collection.find().first().get("a")).isEqualTo(2);
}
代码示例来源:origin: opencb/opencga
public void insertDocument(Object id) {
collection.update(new Document("_id", id),
Updates.set("_id", id),
new QueryOptions(MongoDBCollection.UPSERT, true));
}
}
代码示例来源:origin: creactiviti/piper
@Override
public TaskExecution merge(TaskExecution aTaskExecution) {
collection
.updateOne(
and(eq("_id", aTaskExecution.getJobId()), eq("execution._id", aTaskExecution.getId())),
set(format("{0}.$", DSL.EXECUTION), aTaskExecution)
);
return aTaskExecution;
}
代码示例来源:origin: de.bwaldvogel/mongo-java-server-test-common
@Test
public void testUpsert() throws Exception {
MongoCollection<Document> collection = readOnlyClient.getDatabase("testdb").getCollection("testcollection");
assertThatExceptionOfType(MongoException.class)
.isThrownBy(() -> collection.updateMany(json("{}"), Updates.set("foo", "bar"), new UpdateOptions().upsert(true)))
.withMessageContaining("Command failed with error 59 (CommandNotFound): 'no such command: 'update'");
}
代码示例来源:origin: epam/DLab
/**
* Updates the status of exploratory in Mongo database.
*
* @param dto object of exploratory status info.
* @return The result of an update operation.
*/
public UpdateResult updateExploratoryStatus(StatusEnvBaseDTO<?> dto) {
return updateOne(USER_INSTANCES,
exploratoryCondition(dto.getUser(), dto.getExploratoryName()),
set(STATUS, dto.getStatus()));
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-mallet
private void writeClassificationToMongo(List<Classification> classify) {
classify.forEach(
classification -> {
Instance instance = classification.getInstance();
documentsCollection.findOneAndUpdate(
Filters.eq(new ObjectId((String) instance.getName())),
Updates.set(
CLASSIFICATION_FIELD, classification.getLabeling().getBestLabel().toString()));
});
}
代码示例来源:origin: dstl/baleen
private void writeClassificationToMongo(List<Classification> classify) {
classify.forEach(
classification -> {
Instance instance = classification.getInstance();
documentsCollection.findOneAndUpdate(
Filters.eq(new ObjectId((String) instance.getName())),
Updates.set(
CLASSIFICATION_FIELD, classification.getLabeling().getBestLabel().toString()));
});
}
代码示例来源:origin: epam/DLab
public void updateSchedulerSyncFlag(String user, String exploratoryName, boolean syncFlag) {
final String syncStartField = SCHEDULER_DATA + ".sync_start_required";
UpdateResult result;
do {
result = updateOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName),
elemMatch(COMPUTATIONAL_RESOURCES, and(ne(SCHEDULER_DATA, null), ne(syncStartField, syncFlag)))),
set(computationalFieldFilter(syncStartField), syncFlag));
} while (result.getModifiedCount() != 0);
}
内容来源于网络,如有侵权,请联系作者删除!