Search code examples
mongodbmongodb-shell

How to generate list of documents directly in MongoDB's shell?


I don't wanna use any other language. Just open the MongoDB's shell and create let say 100 000 documents with _id incremented by 1.

Is that possible?


Solution

  • The MongoDB shell is a javascript shell, so you can use anything you can use in javascript:

    > for (var i=0; i<100000; i++) { db.my_collection.insert({i: i}); }