-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonas2.js
59 lines (59 loc) · 4.01 KB
/
personas2.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
show dbs;
use personas;
db;
db.persona.find();
db.persona.find().count();
db.persona.aggregate([]);
db.persona.aggregate({$group: {_id: "$age"}});
db.persona.aggregate({$group: {_id: "$gender"}});
db.persona.aggregate({$group: {_id: "$company"}});
db.persona.aggregate({$group: {_id: "$company.location.country"}});
db.persona.aggregate({$group: {_id: "$name"}});
db.persona.aggregate({$match: {gender: "female"}});
db.persona.aggregate({$match: {eyeColor: "brown"}});
db.persona.aggregate({$match: {age: {$lt: 21}}});
db.persona.aggregate({$group: {_id: {age: "$age", gender: "$gender"}}});
db.persona.aggregate({$group: {_id: {eyeColor: "$eyeColor", gender: "$gender", fruit: "$favoriteFruit"}}});
db.persona.aggregate({$match: {$and: [{gender: "female"}, {eyeColor: "brown"}, {age: {$lt: 21}}]}});
db.persona.aggregate({$match: {isActive: true}});
db.persona.aggregate({$match: {tags: {$size: 3}}});
db.persona.aggregate([{$match: {favoriteFruit: "banana"}}, {$group: {_id: {eyeColor: "$eyeColor", age: "$age"}}}]);
db.persona.aggregate([{$group: {_id: {eyeColor: "$eyeColor", age: "$age"}}}, {$match: {"_id.eyeColor": "blue"}}]);
//db.persona.aggregate([{$count: "allDocumentsCount"}]);//desde v 3.4
db.persona.aggregate([]).toArray().length;
db.persona.aggregate([]).itcount();
//db.persona.aggregate([{$count: "total"}]);//desde v 3.4
db.persona.count();
//db.persona.aggregate({$group: {_id: {eyeColor: "$eyeColor", gender: "$gender"}}}, {$count: "eyeColor"});//desde v 3.4
db.persona.aggregate([{$group: {_id: null, count: {$sum: 1}}}]);
db.persona.aggregate([{$group: {_id: "$age", count: {$sum: 1}}}]);
db.persona.aggregate([{$sort: {age: 1}}]);
db.persona.aggregate([{$sort: {name: 1}}]);
db.persona.aggregate([{$sort: {age: -1, gender: -1, eyeColor: 1}}]);
db.persona.aggregate([{$group: {_id: "$favoriteFruit"}}, {$sort: {_id: 1}}]);
db.persona.aggregate([{$match: {age: {$gte: 25}}}, {$group: {_id: "$age"}}, {$sort: {_id: 1}}]);
db.persona.aggregate([{$group: {_id: {eyeColor: "$eyeColor", favoriteFruit: "$favoriteFruit"}}}, {$sort: {"_id.eyeColor": 1}}]);
db.persona.aggregate([{$project: {name: true, age: true, _id: false}}]);
db.persona.aggregate([{$project: {name: true, age: true, _id: false}}]);
db.persona.aggregate([{$project: {"company.title": true, "company.phone": true, _id: false}}]);
db.persona.aggregate([{$project: {name: 1, newAge: "$age", _id: false}}]);
db.persona.aggregate([{$project: {isActive: 1, name: 1, gender: 1}}]);
db.persona.aggregate([{$project: {_id: 0, name: 1, info: {eyes: "$eyeColor", fruit: "$favoriteFruit", country: "$company.location.country"}}}]);
db.persona.aggregate([{$limit: 100}]);
db.persona.aggregate([{$limit: 100}, {$match: {age: {$gt: 27}}}, {$group: {_id: "$company.location.country"}}]);
db.persona.aggregate([{$limit: 100}, {$match: {eyeColor: {$ne: "blue"}}}, {$group: {_id: {eyeColor: "$eyeColor", favoriteFruit: "$favoriteFruit"}}}, {$sort: {"_id.eyeColor": 1, "_id.favoriteFruit": -1}}]);
db.persona.aggregate([{$group: {_id: "$tags"}}]);
db.persona.aggregate([{$unwind: "$tags"}]);
db.persona.aggregate([{$unwind: "$tags"}, {$project: {_id: 0, name: 1, gender: 1, tags: 1}}]);
db.persona.aggregate([{$unwind: "$tags"}, {$project: {tags: 1, _id: 0}}]);
db.persona.aggregate([{$unwind: "$tags"}, {$group: {_id: "$tags"}}]);
db.persona.aggregate([{$group: {_id: "$age", count: {$sum: 1}}}]);
db.persona.aggregate([{$unwind: "$tags"}, {$group: {_id: "$tags", count: {$sum: 1}}}]);
db.persona.aggregate([{$unwind: "$tags"}, {$group: {_id: "$tags", count: {$sum: 1}}}, {$sort: {count: -1}}]);
db.persona.aggregate([{$group: {_id: "$eyeColor", avgAge: {$avg: "$age"}}}]);
db.persona.aggregate([{$group: {_id: "$eyeColor", minAge: {$min: "$age"}}}]);
db.persona.aggregate([{$group: {_id: "$eyeColor", maxAge: {$max: "$age"}}}]);
//db.persona.aggregate([{$project: {name: 1, eyeColorType: {$type: "$eyeColor"}, ageType: {$type: "$age"}}}]);//desde v 3.4
db.persona.aggregate([{$group: {_id: {age: "$age", eyeColor: "$eyeColor"}}}, {$out: "aggregationResults"}]);
db.aggregationResults.find();
db.persona.aggregate([], {allowDiskUse: true});