| 1 | <h2>Document</h2> |
| 2 | <pre><code> |
| 3 | { |
| 4 | '_id': ObjectId('5ec72ffe00316be87cab3927'), |
| 5 | 'code': Code('function () { return 22; }'), |
| 6 | 'binary': BinData(1, '232sa3d323sd232a32sda3s2d3a2s1d23s21d3sa'), |
| 7 | 'dbref': DBRef('namespace', ObjectId('5ec72f4200316be87cab3926'), 'db'), |
| 8 | 'timestamp': Timestamp(0, 0), |
| 9 | 'long': NumberLong(9223372036854775807), |
| 10 | 'decimal': NumberDecimal('1000.55'), |
| 11 | 'integer': 100, |
| 12 | 'maxkey': MaxKey(), |
| 13 | 'minkey': MinKey(), |
| 14 | 'isodate': ISODate('2012-01-01T00:00:00.000Z'), |
| 15 | 'regexp': RegExp('prism(js)?', 'i'), |
| 16 | 'string': 'Hello World', |
| 17 | 'numberArray': [1, 2, 3], |
| 18 | 'stringArray': ['1','2','3'], |
| 19 | 'randomKey': null, |
| 20 | 'object': { 'a': 1, 'b': 2 }, |
| 21 | 'max_key2': MaxKey(), |
| 22 | 'number': 1234, |
| 23 | 'invalid-key': 123, |
| 24 | noQuotesKey: 'value', |
| 25 | } |
| 26 | </code></pre> |
| 27 | |
| 28 | <h2>Query</h2> |
| 29 | <pre><code> |
| 30 | db.users.find({ |
| 31 | _id: { $nin: ObjectId('5ec72ffe00316be87cab3927') }, |
| 32 | age: { $gte: 18, $lte: 99 }, |
| 33 | field: { $exists: true } |
| 34 | }) |
| 35 | </code></pre> |
| 36 | |
| 37 | |
| 38 | <h2>Update</h2> |
| 39 | <pre><code> |
| 40 | db.users.updateOne( |
| 41 | { |
| 42 | _id: ObjectId('5ec72ffe00316be87cab3927') |
| 43 | }, |
| 44 | { |
| 45 | $set: { age: 30 }, |
| 46 | $inc: { updateCount: 1 }, |
| 47 | $push: { updateDates: new Date() } |
| 48 | } |
| 49 | ) |
| 50 | </code></pre> |
| 51 | |
| 52 | <h2>Aggregate</h2> |
| 53 | <pre><code> |
| 54 | db.orders.aggregate([ |
| 55 | { $sort : { age : -1 } }, |
| 56 | { $project : { age : 1, status : 1, name : 1 } }, |
| 57 | { $limit: 5 } |
| 58 | ]) |
| 59 | </code></pre> |