Skip to content

Add support of $setOnInsert modifier for upsert [DATAMONGO-630] #1551

Closed
@spring-projects-issues

Description

@spring-projects-issues

Anton opened DATAMONGO-630 and commented

Please add support of $setOnInsert modifier for upsert introduced in mongo 2.4 https://jira.mongodb.org/browse/SERVER-340. It will significantly decrease disk I/O in case of bulk-load. In our system multiple threads should create records in the same collection base on input data, _id is a hash of essential values. In our case upsert is only one way how to manage atomic operations, but without setOnInsert this operation is very slow on sharded environment.

Method:

@Override
public void upsertCluster(ClusterKey clusterKey) {
    FindAndModifyOptions options = new FindAndModifyOptions().upsert(true);
    Query query = query(Criteria.where(ID).is(clusterKey.getId()));
    Update update = new Update();
    update.set(CLUSTERS_KEY, clusterKey);
    getMongoTemplate().findAndModify(query, update, options,
        ClusterMongoDocument.class, getDocumentInformation().getCollectionName());
}

Please suggest how can we optimize the method.

Thank you,
Anton


2 votes, 4 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core supporttype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions