1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| db.user.aggregate([ { $project: { _id: 1, name: 1, age: 1, "男":{ $eq: ["$sex", {$literal:1}] } } } ])
输出:
{ "_id" : ObjectId("5e9567bda4e8d95babdea321"), "name" : "张二", "age" : 10, "男" : true } { "_id" : ObjectId("5e95680ea4e8d95babdea322"), "name" : "张三", "age" : 10, "男" : true } { "_id" : ObjectId("5e95680ea4e8d95babdea323"), "name" : "李四", "age" : 11, "男" : true } { "_id" : ObjectId("5e95680ea4e8d95babdea324"), "name" : "王五", "age" : 12, "男" : false } { "_id" : ObjectId("5e95680ea4e8d95babdea325"), "name" : "马六", "age" : 11, "男" : false } { "_id" : ObjectId("5e95680ea4e8d95babdea326"), "name" : "封七", "age" : 13, "男" : false }
|