我们有这样的数据
{ "_id" : 1, title: "abcdef", isbn: "6969696969", author: { last: "codingwhy<span style="font-family: Arial, Helvetica, sans-serif;">", first: "com" },</span> copies: 5 }
现在使用project来变换输出
db.books.aggregate( [ { $project : { title : 1 , author : 1 } } ] )
可以得
{ "_id" : 1, "title" : "abcdef", "author" : { "last" : "codingwhy", "first" : "com" } }在$project里,我们指明(筛选)了要显示的数据,title和author,_id是自带的,可以用 _id:0 来将其过滤掉