Insert Many does not point out collection not found error

Hi,

when i tried to run the script which inserts dates into myMovies collection with out actually creating the same , it executes and throws errors related to the document only like duplicate key error etc .Instead it should have stopped with the message collection does not exists?? How come Mongodb attempts to run it even with out the collection itself??

But as soon as i create the collection ,i could see all the documents available in compass. Please clarify

Regards

Srikanth k

Hi @srikanth_1969,

If the collection does not already exist then the insert(), insertOne() and insertMany() method implicitly creates the collection on successful write.

Either you explicitly create the collection or it’s created for you implicitly as mentioned above, in both the cases it will be reflected in Compass.

Please refer our documentation on insertMany() method if you want to know more about it.

Hope it helps!

Let me know if you have any other question.

Thanks,
Shubham Ranjan
Curriculum Services Engineer