-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2-find2.js
44 lines (41 loc) · 1001 Bytes
/
p2-find2.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
44
var mongo = require('mongodb').MongoClient
mongo.connect('mongodb://localhost:27017/learnyoumongo', function(err, db) {
// db gives access to the database
var collection = db.collection('parrots')
collection.find({
age : {$gt: parseInt(process.argv[2])}
},
{
name: 1
, age: 1
, _id: 0
}).toArray(function(err, documents) {
if (err) console.log("ERROR")
else {
console.log(documents)
}
db.close();
})
})
/* Solution
var mongo = require('mongodb').MongoClient
var age = process.argv[2]
var url = 'mongodb://localhost:27017/learnyoumongo'
mongo.connect(url, function(err, db) {
if (err) throw err
var parrots = db.collection('parrots')
parrots.find({
age: {
$gt: +age
}
}, {
name: 1
, age: 1
, _id: 0
}).toArray(function(err, docs) {
if (err) throw err
console.log(docs)
db.close()
})
})
*/