Can anybody help me with this "some magic" that I am looking for?
I am using Java, Heroku, mLab:MongoDB tech stack.
Assuming the in memory
database is a collection and each document has the id, you can use insertAll
method of MongoTemplate
to dump the whole collection. It will keep the unchanged documents as is and update the others.
As far as upsert
is concerned, you can create a Query
and use upsert
method of MongoTemplate
, eg:
Query query = new Query(Criteria.where("_id").is(my_id));
mongoTemplate.upsert(query, document, Document.class, "collection_name");
Here's the javadoc of insertAll and upsert methods.
Update
If you are using core mongo-java-driver then you can have a look at this and this SO answers to do the same operations.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.