Last active
August 29, 2015 14:08
-
-
Save abarth500/55b9a02bc0f2590558c7 to your computer and use it in GitHub Desktop.
node.jsからmongoDBへの接続コード例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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