mongodb与此查询等效的是什么:
选择"foo"作为bar,
id
作为tablename的"spec"
小智.. 14
可以使用$ project从另一个字段创建具有给定名称和值的新字段:
{ "_id" : 1, title: "abc123", isbn: "0001122223334", author: { last: "zzz", first: "aaa" }, copies: 5 }
以下$ project阶段添加了新字段isbn,lastName和copiesSold:
db.books.aggregate( [ { $project: { title: 1, isbn: { prefix: { $substr: [ "$isbn", 0, 3 ] }, group: { $substr: [ "$isbn", 3, 2 ] }, publisher: { $substr: [ "$isbn", 5, 4 ] }, title: { $substr: [ "$isbn", 9, 3 ] }, checkDigit: { $substr: [ "$isbn", 12, 1] } }, lastName: "$author.last", copiesSold: "$copies" } } ] )
http://docs.mongodb.org/manual/reference/operator/aggregation/project/#pipe._S_project
可以使用$ project从另一个字段创建具有给定名称和值的新字段:
{ "_id" : 1, title: "abc123", isbn: "0001122223334", author: { last: "zzz", first: "aaa" }, copies: 5 }
以下$ project阶段添加了新字段isbn,lastName和copiesSold:
db.books.aggregate( [ { $project: { title: 1, isbn: { prefix: { $substr: [ "$isbn", 0, 3 ] }, group: { $substr: [ "$isbn", 3, 2 ] }, publisher: { $substr: [ "$isbn", 5, 4 ] }, title: { $substr: [ "$isbn", 9, 3 ] }, checkDigit: { $substr: [ "$isbn", 12, 1] } }, lastName: "$author.last", copiesSold: "$copies" } } ] )
http://docs.mongodb.org/manual/reference/operator/aggregation/project/#pipe._S_project