我有一个结构如下的“书籍”集合:
{
"isbn" : 101,
"title" : "One",
"author" : "Mike",
"year" : 1980,
"awards" : [
{"award" : "Nebula", "year" : 1987},
{"award" : "Hugo", "year" : 1985},
],
"reviews" : [
{"user_id" : 1, "rating" : 10, "text" : "Awesome book"},
{"user_id" : 2, "rating" : 4, "text" : "Terrible book"},
{"user_id" : 5, "rating" : 7, "text" : "Good book"},
]
}
例如,我只想选择评分高于 5 的评论对象(而不是整个文档),这样我的结果将如下所示:
"reviews" : [
{"user_id" : 1, "rating" : 10, "text" : "Awesome book"},
{"user_id" : 5, "rating" : 7, "text" : "Good book"},
]
我该如何编写 db.books.find() 查询来做到这一点?