本文整理了Java中com.mongodb.client.model.Updates.push()
方法的一些代码示例,展示了Updates.push()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Updates.push()
方法的具体详情如下:
包路径:com.mongodb.client.model.Updates
类名称:Updates
方法名:push
[英]Creates an update that adds the given value to the array value of the field with the given name.
[中]创建一个更新,将给定值添加到具有给定名称的字段的数组值中。
代码示例来源:origin: creactiviti/piper
@Override
public void create(TaskExecution aTaskExecution) {
collection
.updateOne(
eq("_id", aTaskExecution.getJobId()),
push(DSL.EXECUTION, aTaskExecution)
);
}
代码示例来源:origin: opencb/opencga
bsons.add(set(studyIdStr + '.' + NEW_STUDY_FIELD, false));
} else if (binaryList.size() == 1) {
bsons.add(resumeStageLoad ? addToSet(fieldName, binaryList.get(0)) : push(fieldName, binaryList.get(0)));
} else {
bsons.add(resumeStageLoad ? addEachToSet(fieldName, binaryList) : pushEach(fieldName, binaryList));
代码示例来源:origin: opencb/opencga
@Override
public void nativeInsert(Map<String, Object> project, String userId) throws CatalogDBException {
Bson query = Filters.and(Filters.eq(UserDBAdaptor.QueryParams.ID.key(), userId),
Filters.ne(UserDBAdaptor.QueryParams.PROJECTS_ID.key(), project.get(QueryParams.ID.key())));
Bson update = Updates.push("projects", getMongoDBDocument(project, "project"));
//Update object
QueryResult<UpdateResult> queryResult = userCollection.update(query, update, null);
if (queryResult.getResult().get(0).getModifiedCount() == 0) { // Check if the project has been inserted
throw new CatalogDBException("Project {" + project.get(QueryParams.ID.key()) + "\"} already exists for this user");
}
}
代码示例来源:origin: opencb/opencga
updates.add(push(STUDIES_FIELD, studyDocument));
代码示例来源:origin: de.otto.edison/edison-mongo
@Override
public void appendMessage(final String jobId, final JobMessage jobMessage) {
collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).updateOne(eq(ID, jobId), push(JobStructure.MESSAGES.key(), encodeJobMessage(jobMessage)));
}
代码示例来源:origin: otto-de/edison-microservice
@Override
public void appendMessage(final String jobId, final JobMessage jobMessage) {
collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).updateOne(eq(ID, jobId), combine(push(JobStructure.MESSAGES.key(), encodeJobMessage(jobMessage)), set(JobStructure.LAST_UPDATED.key(), Date.from(jobMessage.getTimestamp().toInstant()))));
}
代码示例来源:origin: epam/DLab
/**
* Add the user's computational resource for notebook into database.
*
* @param user user name.
* @param exploratoryName name of exploratory.
* @param computationalDTO object of computational resource.
* @return <b>true</b> if operation was successful, otherwise <b>false</b>.
*/
public boolean addComputational(String user, String exploratoryName, UserComputationalResource computationalDTO) {
Optional<Document> optional = findOne(USER_INSTANCES,
and(exploratoryCondition(user, exploratoryName),
elemMatch(COMPUTATIONAL_RESOURCES,
eq(COMPUTATIONAL_NAME, computationalDTO.getComputationalName())))
);
if (!optional.isPresent()) {
updateOne(USER_INSTANCES,
exploratoryCondition(user, exploratoryName),
push(COMPUTATIONAL_RESOURCES, convertToBson(computationalDTO)));
return true;
} else {
return false;
}
}
代码示例来源:origin: opencb/opencga
@Override
public QueryResult<User.Filter> addFilter(String userId, User.Filter filter) throws CatalogDBException {
long startTime = startQuery();
// Insert the filter
Bson bsonQuery = Filters.and(
Filters.eq(QueryParams.ID.key(), userId),
Filters.ne(QueryParams.CONFIGS_FILTERS_NAME.key(), filter.getName())
);
Bson filterDocument = getMongoDBDocument(filter, "Filter");
Bson update = Updates.push(QueryParams.CONFIGS_FILTERS.key(), filterDocument);
QueryResult<UpdateResult> queryResult = userCollection.update(bsonQuery, update, null);
if (queryResult.first().getModifiedCount() != 1) {
if (queryResult.first().getModifiedCount() == 0) {
throw new CatalogDBException("Internal error: The filter could not be stored.");
} else {
// This error should NEVER be raised.
throw new CatalogDBException("User: There was a critical error when storing the filter. Is has been inserted "
+ queryResult.first().getModifiedCount() + " times.");
}
}
return endQuery("addFilter", startTime, Arrays.asList(filter));
}
代码示例来源:origin: epam/DLab
/**
* Add the user's library for exploratory into database.
*
* @param user user name.
* @param exploratoryName name of exploratory.
* @param library library.
* @return <b>true</b> if operation was successful, otherwise <b>false</b>.
*/
public boolean addLibrary(String user, String exploratoryName, LibInstallDTO library, boolean reinstall) {
Optional<Document> opt = findOne(USER_INSTANCES,
and(exploratoryCondition(user, exploratoryName),
libraryConditionExploratory(library.getGroup(), library.getName(), library.getVersion())));
if (!opt.isPresent()) {
updateOne(USER_INSTANCES,
exploratoryCondition(user, exploratoryName),
push(EXPLORATORY_LIBS, convertToBson(library)));
return true;
} else {
Document values = updateLibraryFields(library, null);
if (reinstall) {
values.append(libraryFieldFilter(LIB_INSTALL_DATE), null);
values.append(libraryFieldFilter(LIB_ERROR_MESSAGE), null);
}
updateOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName),
libraryConditionExploratory(library.getGroup(), library.getName(), library.getVersion())),
new Document(SET, values));
return false;
}
}
代码示例来源:origin: epam/DLab
updateOne(USER_INSTANCES,
runningExploratoryAndComputationalCondition(user, exploratoryName, computationalName),
push(COMPUTATIONAL_LIBS + "." + computationalName, convertToBson(library)));
return true;
} else {
代码示例来源:origin: opencb/opencga
Bson update = Updates.push("projects", projectDocument);
代码示例来源:origin: opencb/opencga
@Override
public QueryResult<VariableSet> createVariableSet(long studyId, VariableSet variableSet) throws CatalogDBException {
long startTime = startQuery();
if (variableSetExists(variableSet.getId(), studyId) > 0) {
throw new CatalogDBException("VariableSet { name: '" + variableSet.getId() + "'} already exists.");
}
long variableSetId = getNewId();
variableSet.setUid(variableSetId);
Document object = getMongoDBDocument(variableSet, "VariableSet");
object.put(PRIVATE_UID, variableSetId);
Bson bsonQuery = Filters.eq(PRIVATE_UID, studyId);
Bson update = Updates.push("variableSets", object);
QueryResult<UpdateResult> queryResult = studyCollection.update(bsonQuery, update, null);
if (queryResult.first().getModifiedCount() == 0) {
throw new CatalogDBException("createVariableSet: Could not create a new variable set in study " + studyId);
}
return endQuery("createVariableSet", startTime, getVariableSet(variableSetId, null));
}
代码示例来源:origin: opencb/opencga
@Override
public QueryResult<VariableSet> addFieldToVariableSet(long variableSetId, Variable variable, String user)
throws CatalogDBException, CatalogAuthorizationException {
long startTime = startQuery();
QueryResult<VariableSet> variableSet = getVariableSet(variableSetId, new QueryOptions(), user);
checkVariableNotInVariableSet(variableSet.first(), variable.getId());
Bson bsonQuery = Filters.eq(QueryParams.VARIABLE_SET_UID.key(), variableSetId);
Bson update = Updates.push(QueryParams.VARIABLE_SET.key() + ".$." + VariableSetParams.VARIABLE.key(),
getMongoDBDocument(variable, "variable"));
QueryResult<UpdateResult> queryResult = studyCollection.update(bsonQuery, update, null);
if (queryResult.first().getModifiedCount() == 0) {
throw CatalogDBException.updateError("VariableSet", variableSetId);
}
if (variable.isRequired()) {
dbAdaptorFactory.getCatalogSampleDBAdaptor().addVariableToAnnotations(variableSetId, variable);
dbAdaptorFactory.getCatalogCohortDBAdaptor().addVariableToAnnotations(variableSetId, variable);
dbAdaptorFactory.getCatalogIndividualDBAdaptor().addVariableToAnnotations(variableSetId, variable);
dbAdaptorFactory.getCatalogFamilyDBAdaptor().addVariableToAnnotations(variableSetId, variable);
dbAdaptorFactory.getCatalogFileDBAdaptor().addVariableToAnnotations(variableSetId, variable);
}
return endQuery("Add field to variable set", startTime, getVariableSet(variableSetId, null));
}
内容来源于网络,如有侵权,请联系作者删除!