Created
February 8, 2016 14:26
-
-
Save dapangmao/8703aee62efd5cd9f6fc to your computer and use it in GitHub Desktop.
chapter 1
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
var mongodb = require('mongodb'); | |
var uri = 'mongodb://localhost:27017/example'; | |
mongodb.MongoClient.connect(uri, function(error, db) { | |
if (error) { | |
console.log(error); | |
process.exit(1); | |
} | |
db.collection('sample').insert({ x: 1 }, function(error, result) { | |
if (error) { | |
console.log(error); | |
process.exit(1); | |
} | |
db.collection('sample').find().toArray(function(error, docs) { | |
if (error) { | |
console.log(error); | |
process.exit(1); | |
} | |
console.log('Found docs:'); | |
docs.forEach(function(doc) { | |
console.log(JSON.stringify(doc)); | |
}); | |
process.exit(0); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment