Skip to content

Instantly share code, notes, and snippets.

@abarth500
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save abarth500/55b9a02bc0f2590558c7 to your computer and use it in GitHub Desktop.

Select an option

Save abarth500/55b9a02bc0f2590558c7 to your computer and use it in GitHub Desktop.
node.jsからmongoDBへの接続コード例
/* mongoDB */
use data_eng
db.winelist.insert({name:"シャブリ",color:"white"})
db.winelist.insert({name:"ジュヴレシャンベルタン",color:"red"})
db.winelist.insert({name:"サンテミリオン",color:"red"})
db.winelist.insert({name:"オーメドック",color:"red"})
db.winelist.insert({name:"サンセール",color:"white"})
db.winelist.find({color:"red"})
exit
/* Node.js */
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/data_eng', function (err, db) {
db.collection("winelist").find({color:"red"}).toArray(function(err,bottles){
for(c = 0;c <bottles.length;c++){
var bottle = bottles[c];
console.log(bottle.name);
};
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment