-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb.js
More file actions
33 lines (29 loc) · 785 Bytes
/
Copy pathmongodb.js
File metadata and controls
33 lines (29 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var MongoClient = require('mongodb').MongoClient;
var mongodbURI = process.env.MONGOHQ_URL ||
'mongodb://127.0.0.1:27017/nodeintro';
MongoClient.connect(mongodbURI, function (err, db) {
if (err) {
console.error('Oh no, connection troubles!', err);
return;
}
db.collection('testcol').insert({
nick: 'tidoust',
firstName: 'Francois',
lastName: 'Daoust'
}, function (err, result) {
if (err) {
console.error('Insertion failed', err);
process.exit(1);
}
console.log('Inserted', result);
db.collection('testcol').findOne({
nick: 'tidoust'
}, function (err, result) {
if (err) {
console.error('Could not read DB', err);
process.exit(1);
}
console.log('Found', result);
});
});
});