Do you want to read data from a CSV file and import into mongodb? You can create a script file (javascript) and use the mongo shell to execute it, as described in the " shell script ".
Sample session, test database, starting with an empty foo collection:
> db.foo.insert({name : "james", position : "forward"}) > db.foo.find() { "_id" : ObjectId("4f0c99f6cb435f1e7d7fedea"), "name" : "james", "position" : "forward" } >
then you create your script let say mongo_scripting.js:
db.foo.insert({name : "wade", position : "guard"}); db.foo.update({name : "james"}, {$set : {position : "power forward"}}, false, true);
and run the script:
mongo localhost:27017/test mongo_scripting.js
Return to Mongo:
> db.foo.find() { "_id" : ObjectId("4f0c99f6cb435f1e7d7fedea"), "name" : "james", "position" : "power forward" } { "_id" : ObjectId("4f0c9a64a4a4642bae6459ea"), "name" : "wade", "position" : "guard" } >
you see that one document has been updated and one new inserted.
An alternative is to use the java / python driver ... to load data.
milan source share