How to insert large amount of data into MongoDB efficiently, instead of typing every single collection?

114 views Asked by At

I'm trying to build REST API with Node JS and MongoDB. I'm using MongoDB Atlas (https://www.mongodb.com/cloud/atlas). I need to insert large amount of data (200 of country names, city name and etc). The schema for single country looks like :

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const countrySchema = new Schema({
  name: { type: String, required: true }
});

const Country = mongoose.model('Country',countrySchema);

module.exports = Country; 

So, in order to insert country names I need to write each time every country name separately : " { "name" : "countryName" } "

Is there any way of inserting all countries at the same time with following above Schema?

Thanks in advance for help.

0

There are 0 answers