在books这个集合里有一个document存储的结构如图一所示,想要查找指定id的document里面指定id的chapter的内容(返回chapter的内容而非整个document):
db.books.find(
{ _id: ObjectId("5c493680d2267584d574f306") },
{ chapters:{ $elemMatch:{ _id:ObjectId("5c49659df378e4c907f54b47") } } }
)
结果将返回图二所示chapter的内容