While doing hands-on on InsertOne, I did following:
It should have created new collection for me with name as moviesScratch and insert a document into it. but neither I got any error nor new collection was created. Where this document is inserted?
For more details, please see attached screenshot wherein I have highlighted DB, collections and documents.
MongoDB will create a collection if you run insertOne and if it does not exist before.
But it is not true reversibly, if you are looking at show collections before doing an insertOne , then it won’t be showing the collection. You have to check after you have performed an insert operation.
Lets take a look step-wise:
The steps you have taken and my understanding is:
You have run show collections which does not show moviesScratch.
** You may have not run insertOne on moviesScratch yet.
You are running db.moviesScratch.insertOne , and it shows acknowledged: True
** It means the collection must have been created and the document should be inserted there.
You are running db.movieScratch.insertOne, it also shows acknowledged: True.
** It means you got one document inserted in movieScratch.
Run show collections under video database now, it will be showing moviesScratch: