How to create the .js file which is use to import database in sandbox cluster?

Hi guys,

I understand how to import the database from one cluster to another by using load function with respective .js file.But i am not able to understand how to create that .js file which we use to load in another cluster.

Thanks

You do not need a JavaScript file.

See
https://docs.mongodb.com/manual/reference/program/mongoimport/
https://docs.mongodb.com/manual/reference/program/mongoexport/
https://docs.mongodb.com/manual/reference/program/mongodump/
https://docs.mongodb.com/manual/reference/program/mongorestore/

1 Like

NO no i am not taling asking about mongodb import function,
In chapter 2 shanon use load function to import database (not a collection ) from one mongodb cluster to sandbox cluster by using command load(“xyz.js”) after that existing database got imported in sandbox cluster.
So my doubt was how to create that xyz.js file?

The load() function has nothing to do about loading data. See

https://docs.mongodb.com/manual/reference/method/load/

It is used to run a JavaScript. In the particular case of this chapter, it is used to populate the database. To see how to do it you have to look at the script. You must know JavaScript to understand how they do it. Learning JavaScript is outside the scope of M001. You may take M220JS which is JavaScript related. But if you do not know JavaScript it might be not so easy.

To populate the .js file there is one way that i know. First you have to create a csv file (excel file). Then you can convert that file to .js file easily using some online tools. You can google “csv to js” and you find multiple options.

1 Like

If you are going to use Excel to create a .csv you might as well create the .csv directly.

If you are going to create a .csv file you might as well create the .json directly.

If you are going to create a .json file you might as well use mongoimport directly with the .json file and skip the .js file with load().

They, the mongo university team, probably decided to go with load(…) because it is simpler for the student to execute.

If you look at loadMovieDetailsDataset.js you will see it is only 3 lines of code. They select the database, they drop the collection and then they insertMany(). It is more or less a mongoimport with –drop and other appropriate command line options. More complicate and simpler at the same time depending on the context.

1 Like

Ohhh Understood everything ,Thank you so much guys.
much appreciated.

1 Like

Welcome @Akshay_Pandhare_59256 and @Owaisqayyum to our M001 discussion forum :slight_smile:.

Just a little bit of clarification on this :

If I am not mistaken, In this course we do not import/migrate data from one cluster to another. Can you please point out the name of the video lecture that you are referring to ?

I think the documentation links shared by @steevej-1495 in post #2 would give a good idea about how to get data in and out of the MongoDB.

Using mongoimport, you can import data stored in JSON, CSV or TSV files.

Thanks,
Shubham Ranjan
Curriculum Services Engineer