Skip to content

Instantly share code, notes, and snippets.

@nanusdad
Last active January 30, 2019 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanusdad/c79d112d46bdc6544b3dc03bf57ca1a3 to your computer and use it in GitHub Desktop.
Save nanusdad/c79d112d46bdc6544b3dc03bf57ca1a3 to your computer and use it in GitHub Desktop.
Inserting data from JSON files into mongo

Inserting data into mongo collection from JSON file

var file = cat('./20-new.json');  # file name
use testdb                        # db name
var o = JSON.parse(file);         # convert string to JSON
db.forms.insert(o)                # collection name

Inserting data using 'meteor mongo' into collection from JSON file

var file = cat('./20-new.json');        # file name
var o = JSON.parse(file);               # convert string to JSON

o.forEach(function (f) { 
  f._id = ObjectId().valueOf();         # set _id to value that will work with Meteor
  f.Date = ISODate(f.Date);             # need convert dates to ISODate
  f.dob = ISODate(f.dob); 
  f.doj = ISODate(f.doj); 
  db.students.insert(f);                # insert on item into collection
  }
 );           
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment