I need to insert documents on MongoDB (with specific id instead of auto generated ObjectID) using java..
To insert one document or update if exist, I tried use
findOne
to search for the id, if it doesn't exist theninsert
the id and thenfindAndModify
. It works but I don't feel that it's efficient way, it's time consuming. Is there a better way to achieve that?To insert multiple documents at once,I'm following this solution. but I don't know how I can insert my custom Id instead of objectID?
Any help will be appreciated