-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb
More file actions
executable file
·64 lines (27 loc) · 938 Bytes
/
mongodb
File metadata and controls
executable file
·64 lines (27 loc) · 938 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
34
35
36
37
38
var c = db.collection.find()
var doc = function() {return c.hasNext() ? c.next() : null;}
c.objsLeftInBatch()
-projection
db.collection.find({rated: 'PG'}, {title: 1, -id: 0}).pretty()
-comparison query operators
$eq $gt $gte $in $lt $lte $ne $nin
db.collection.find({rated: {$in: ['G', 'PG']}}, {title: 1, rated: 1, _id: 0})
-element
$exists $type
db.collection.find({'tomato.meter': {$exists: true})
db.collection.find({'_id': {$type: 'string'}}).count()
-logical
$or $and $not $nor
db.collection.find( { $or: [ { '': {} }, { '': {} } ] } )
$regex
db.collection.find( { "": { $regex: } } )
-array
$all $elemMatch $size
db.collection.find( { genres: { $all: ["", "", ""] } } )
-update
db.collection.updateOne( {title: "the martian"}, { $set: { poster: } } )
db.collection.replaceOne()
db.collection.find( { runtime: { $gt:90, $lt:120 }}, { _id:0, title:1, runtime:1 } )
mongoimport
show dbs
use 'db'