Loading data set into collection

I have two collections in my database. If i load the data set using load() from the mongo shell, in which collections does the data set gets loaded into?

If you do that you will get errors. Load is used to execute JavaScript files. The document for load is https://docs.mongodb.com/manual/reference/method/load/

To import .json data into a collection use https://docs.mongodb.com/manual/reference/program/mongoimport/

1 Like

Hi @Krithika_57070,

As @steevej-1495 mentioned, load() function loads and runs a JavaScript file into the current shell environment.

If you are asking this question in reference to the loadReviewsDataset.zip file then I would recommend you to unzip the file and then open the loadReviewsDataset.js file.

The first three lines will answer your question :slight_smile:

db = db.getSiblingDB("video");
db.movieDetails.drop();
db.movieDetails.insertMany([
{"title":"Once Upon a Time in the West","year":1968,"rated":"PG-13","runtime":175,"countries""countries":["Italy","USA","Spain"],"genres":["Western"],"director":"Sergio Leone","writers":["Sergio Donati","Sergio Leone","Dario Argento","Bernardo Bertolucci","Sergio Leone"],"actors":["Claudia Cardinale","Henry Fonda","Jason Robards","Charles Bronson"],"plot":"Epic story of a mysterious stranger with a harmonica who joins forces with a notorious desperado to protect a beautiful widow from a ruthless assassin working for the railroad.","poster":"http://ia.media-imdb.com/images/M/MV5BMTEyODQzNDkzNjVeQTJeQWpwZ15BbWU4MDgyODk1NDEx._V1_SX300.jpg","imdb":{"id":"tt0064116","rating":8.6,"votes":201283},"tomato":{"meter":98,"image":"certified","rating":9,"reviews":54,"fresh":53,"consensus":"A landmark Sergio Leone spaghetti western masterpiece featuring a classic Morricone score.","userMeter":95,"userRating":4.3,"userReviews":64006},"metacritic":80,"awards":{"wins":4,"nominations":5,"text":"4 wins \u0026 5 nominations."},"type":"movie"},
.....
.....
])

Here, the first line of the code points the db variable to the video database.

db = db.getSiblingDB("video");

Second line drops the movieDetails collection from the video database if in case it exists.

db.movieDetails.drop();

This line inserts the data into the movieDetails collection.

db.movieDetails.insertMany([
{"title":"Once Upon a Time in the West","year":1968,"rated":"PG-13","runtime":175,"countries""countries":["Italy","USA","Spain"],"genres":["Western"],"director":"Sergio Leone","writers":["Sergio Donati","Sergio Leone","Dario Argento","Bernardo Bertolucci","Sergio Leone"],"actors":["Claudia Cardinale","Henry Fonda","Jason Robards","Charles Bronson"],"plot":"Epic story of a mysterious stranger with a harmonica who joins forces with a notorious desperado to protect a beautiful widow from a ruthless assassin working for the railroad.","poster":"http://ia.media-imdb.com/images/M/MV5BMTEyODQzNDkzNjVeQTJeQWpwZ15BbWU4MDgyODk1NDEx._V1_SX300.jpg","imdb":{"id":"tt0064116","rating":8.6,"votes":201283},"tomato":{"meter":98,"image":"certified","rating":9,"reviews":54,"fresh":53,"consensus":"A landmark Sergio Leone spaghetti western masterpiece featuring a classic Morricone score.","userMeter":95,"userRating":4.3,"userReviews":64006},"metacritic":80,"awards":{"wins":4,"nominations":5,"text":"4 wins \u0026 5 nominations."},"type":"movie"},
.....
.....
])

Hope it helps!

If you have any other query then please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer