If you really want to use only mongoshell, you can use the cat () command and do the following (txt is not required, this is exactly how my file was named):
use wordlists var file = cat('path/to/yourFile.txt'); // read the file var words = file.split('\n'); // create an array of words for (var i = 0, l = words.length; i < l; i++){ // for every word insert it in the collection db.rockyou.insert({'word': words[i]}); }
This was tested on Mongo 3.0.1 and produced something like:
{ "_id" : ObjectId("551491ee909f1a779b467cca"), "word" : "123456" } { "_id" : ObjectId("551491ee909f1a779b467ccb"), "word" : "12345" } ... { "_id" : ObjectId("551491ee909f1a779b467cd3"), "word" : "abc123" }
But I would apply the logic here (e.g. with python):
import pymongo connection = pymongo.Connection() collection = connection.wordlists.rockyou with open('path/to/yourFile.txt') as f: for word in f.readlines(): collection.insert({'word': word.rstrip()})
source share