Search code examples
mongodbmongodb-querymongoimport

query in mongodb atlas to verify the existence of multiple specific documents in a collection


I have a mongodb collection called employeeInformation, in which I have two documents:

{"name1":"tutorial1"}, {"name2":"tutorial2"}

When I do db.employeeInformation.find(), I get both these documents displayed. My question is - is there a query that I can run to confirm that the collection contains only those two specified documents? I tried db.employeeInformation.find({"name1":"tutorial1"}, {"name2":"tutorial2"}) but I only got the id corresponding to the first object with key "name1". I know it's easy to do here with 2 documents just by seeing the results of .find(), but I want to ensure that in a situation where I insert multiple (100's) of documents into the collection, I have a way of verifying that the collection contains all and only those 100 documents (note I will always have the objects themselves as text). Ideally this query should work in mongoatlas console/interface as well.


Solution

  • db.collection.count()

    will give you number of inserts once you have inserted the document.

    Thanks, Neha