-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (26 loc) · 711 Bytes
/
index.js
File metadata and controls
30 lines (26 loc) · 711 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
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);
}
var val = Math.floor(Math.random()* (1000 - 0) + 0);
db.collection('sample').insert({ x: val }, 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);
});
});
});