Error with insertOne command in shell

trying to insert one document using the shell, throwing a syntax error. Help me with the solution.


1 Like

HI @Sriram_85196,

You are facing this issue because there is an extra space in the Collection Name i.e “Movie scratch” .

You can either change the Collection name to “MovieScratch” and then issue the insertOne() query.

You can also use the db.getCollection to perform any query in the collection if the Collection name contains any special character(space in Collection name in this case) as follows:

db.getCollection(“Movie scratch”).insertOne({“title”:“mazili”, “year”: 2019, “imdb”; “tt3456”})

Please refer to the following doc to get more information about the getCollection() method:

I hope it helps!!

If you have any other doubt, please let me know.


Thank you @Sonali_Mamgain . it works :+1:

when i use video database,its showing only movies collections in shell.

Iam not able to see movieDetails and movieScratch in shell

I can see it mongodb compass

You might have connected to wrong cluster
Please check again
How did you load/insert the data?I mean the connect string you used

Hi @SUJANA_42894,

You are connected to the wrong cluster. Please connect to your Sandbox cluster and you would be able to see the dataset.

In the M001 course, we use two different clusters - Class atlas cluster and Sandbox clsuter.

  1. Class atlas cluster

    This cluster is owned by MongoDB and our learners have read only access. In this cluster we have movies collection inside the video database.

  2. Sandbox cluster

    This is the cluster which you were asked to create in the Lab 2.0: Create an Atlas Sandbox Cluster. After loading the dataset in this cluster you will have the movieDetails collection inside the video database.

Hope it helps!

Shubham Ranjan
Curriculum Support Engineer

I’ve created sandbox cluster but the one collection we created movie Scratch collection but its not loading in shell, I’ve seen your replies in discussion community but I’m confused because we only dealt with one cluster i don’t know about 2.

Hi @Noor_45033,

Please check my previous reply to you here in this post where I have explained about the 2 clusters that we use in this class. The same has been mentioned in the post #6.

Can you please share the command that you used to load the movieScratch dataset into your sandbox cluster ?

A screenshot with the output would be more helpful.

Shubham Ranjan
Curriculum Services Engineer