-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrud-example-nested.js
43 lines (38 loc) · 1.07 KB
/
crud-example-nested.js
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
34
35
36
37
38
39
40
41
42
43
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 doc = {
title: 'Jaws',
year: 1975,
director: 'Steven Spielberg',
rating: 'PG',
ratings: {
critics: 80,
audience: 97
},
screenplay: ['Peter Benchley', 'Carl']
};
db.collection('movies').insert(doc, function(err, result){
if(err){
console.log(err);
process.exit(1);
}
db.collection('movies').
find({ screenplay: 'Peter Benchley' }).
toArray(function(err, docs){
if(err){
console.log(err);
process.exit(1);
}
console.log('Found docs:');
docs.forEach(function(doc){
console.log(JSON.stringify(doc));
});
process.exit(0);
});
});
});