I'm very new to MongoDB (about 4 days in) and I'm trying to insert documents into my collection from within a remote method using Loopback without adding duplicate documents.
I firstly tested adding documents as such:
Events.create(resultData);
Which worked without issue.
I then moved on to trying to add a document without adding duplicates a few other answers:
Events.update(data,data,{upsert: true});
However, this did not add anything to the database.
I decided to move on and try and see if I could first check to see if a document could be found from a collection and therefore not add the document. Similar to this answer.
if(Events.find({itemOfData: resultData.itemOfData},{limit: 1}).size < 1){
Events.create(resultData);
}
However, as before it doens't create any documents.
I'm not sure what to try next or whether my implementation of the above solutions is faulty.