How to efficiently post a document to MongoDB without checking if it is already in the collection. Currently, in my JAVA code, I am checking for the existence of document first and then if it is not where I post it. It seems this is very slow because for every document I am placing two queries.
Can't it be possible to just post the document and MongoDB handle it automatically that if there is already an existing document, just overwrite it else create a new document?
My document structure:
{
"_id": "my unique id string",
"name": "name1",
"Address":{
"street": "street 1",
"country": "NZ",
}
}
I am checking the existence of a document by comparing the "_id" field.