Creating Documents: insertMany()

Hi. In lesson you saying that you pasting to run the command in our shell. I don`t understand where exacly i need to run it. I tried to run bellow command in - cmd (windows 10) and also in -Node.js command prompt.
Command: db.moviesScrtch.insertMany([{"_id": "tt0084726", "title: "Star Trek 2: The Wrath of Khan", "year": 1982, "type": "movie"}, {"_id": "tt0796366", "title: "Star Trek", "year": 2009, "type": "movie"}, {"_id": "tt0084726", "title: "Star Trek 2: The Wrath of Khan", "year": 1982, "type": "movie"}, {"_id": "tt1408101", "title: "Star Trek Into Darkness", "year": 2013, "type": "movie"}, {"_id": "tt0117731", "title: "Star Trek: First Contact", "year": 1982, "type": "movie"}]);

I tried also in shell, please see the second picture
Screenshot (38)
What i am doing wrong?
Screenshot (37)

@Shubham_Ranjan Testing mention

Hi @Semion_79117,

Please use mongo shell to insert these documents into your collection.

As I can see in the screenshot you have a lot of syntax errors. Let’s first do some clean up and then we will insert the data.

Run the following commands to remove the MoviesScratch and MoviesScrtch collection from your database :

use video



Now, go to the Handouts section of the video lecture and download the files. Post that copy-paste the content of the file into your mongo shell.

Please refer our documentation if you want to know more about the insertMany() method and also to know the difference between Ordered Inserts and Unordered Inserts.

Hope it helps!

Please feel free to get back to us if you have any other query.

Shubham Ranjan
Curriculum Services Engineer

Now I have a new problem. I didn`t change anyting, so i need to find out how to reolve this to do all yours instruction. I have in favourite: mongodb://

and other: mongodb:// in Recent.

So, through favorite link i can connect but this is another server then it was yesterday and I’m confused what is what

Can I continue in my MongoDB Compass from my favorite connection (mongodb:// ) to copy-paste there?
I think i got it, the mongo shell is that window

As discobot said : “One advantage of talking to yourself is that you know at least somebody’s listening.” :rofl:

you mean to copy-paste "insertMany-ordered (1) and “insertMany-unordered” files to c/programms files/mongodb/server/4.2/bin folder? or to copy-paste them to the cluster (from the favorite)?
If you mean I need to open .js (I don`t know how to do it yet) file to see what inside (to the content of the file)?

sorry for my English and for my questions, I am desire to learn how to build DB and all of my knowledge in that topic is how to work with exel :frowning:
I open them by cmd and somting was run, I hope I did the right step.
I learnd to open them by edit :slight_smile: is Class cluster which is a read only DB
You cannot do read write operations on this DB

Please use your own Sandbox
The snapshot you displayed is default connection to port 27107 on Windows
Don’t use this

If I understand you correct, in my MongoDB Compass -Connect , In line - Paste your connection string (SRV or Standard ) I need to paste something that include [] to connect.
When I use this string: mongodb+srv://
I get: “Server selection timed out after 30000 ms”

When I use this string: mongodb://
I get: “An error occurred while loading navigation: ‘not master and slaveOk=false’: It is recommended to change your read preference in the connection dialog to Primary Preferred or Secondary Preferred or provide a replica set name for a full topology connection.”

I confused. I think i need to change the port in second string to connect becuse you say - dont use it. Then what port i need to write there? I did the lesson step by step and evrything was good, I dont understand what heppend.

I tryed to go back to lessons and now in Connecting to Your Sandbox Cluster from Compass Lesson, in a second 29 of the lesson he show where to choice primary. But I get

. So now I even cant to start again. I dont know what to do.

I am not clear what issue you are facing but i can connect to your Sandbox cluster by both shell and Compass

This is what i see

mongo “mongodb+srv://” --username m001-student --password m001-mongodb-basics
MongoDB shell version v4.0.5
connecting to: mongodb://,,

Error while trying to show server startup warnings: user is not allowed to do action [getLog] on [admin.]
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show dbs
admin 0.000GB
local 1.438GB
video 0.001GB
MongoDB Enterprise Cluster0-shard-0:PRIMARY> use video
switched to db video
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show collections
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

I use older version of Compass.So i use different connection parameters

May be Shubham_Ranjan can help you better on your connectivity issues

1 Like

Thanks @Ramachandra_37567 for being so helpful to our learners in the discussion forum :slight_smile: .

Hi @Semion_79117,

In this course we are having two clusters.

This one ( :arrow_right: jxeqq ) is the class atlas cluster. This cluster is owned by MongoDB and the user credentials shared with you in the course has read-only role assigned to it so you cannot insert, delete or update data in this cluster. This is only used for querying purpose.

This one is your Sandbox cluster, which you created in this Chapter 2 - Lab 2.0: Create an Atlas Sandbox Cluster. You are the owner of this cluster with read-write role assigned to the user that you created.

Now, coming back to your original problem mentioned in post #1 :

You want to load the data provided in this video lecture [Chapter 2: Creating Documents: insertMany()] into your sandbox cluster. For doing that please follow the instructions mentioned below :

  1. Download the .js file from the handouts section of course lecture as shown above in post #3.

  2. Connect to your Sandbox cluster from the mongo shell (Command line/ power shell of your Windows OS ). Use this connection string :

    mongo "mongodb+srv://" -u m001-student -p m001-mongodb-basics
  3. Once you are connected to the cluster please run this command to switch to the video database.

    use video

  4. Open the .js file and copy-paste the data into the mongo shell prompt.

Keep in mind that for ordered insert you will get a duplicate key error and insertion of documents will stop after that.

Regarding your other issue - We will get into that once this issue has been resolved.

Hope it helps!

Shubham Ranjan
Curriculum Services Engineer

Thank You! @Shubham_Ranjan and @Ramachandra_37567

Hi @Semion_79117,

I’m glad your issue got resolved. Please feel free to get back to us if you have any other query.

Shubham Ranjan
Curriculum Services Engineer