Reputation: 615
Can anybody help me with this "some magic" that I am looking for?
I am using Java, Heroku, mLab:MongoDB tech stack.
Upvotes: 0
Views: 2153
Reputation: 30849
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
, e.g.:
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.
Upvotes: 1