简体   繁体   English

通过子-子文档ID查询文档

[英]Querying documents by sub-sub document id

I have the following schema's: 我有以下架构:

var Post = new mongoose.Schema({
 'responses': [Response]
});

var Response = new mongoose.Schema({
 'question': Question
});

var Question = new mongoose.Schema({
 'id': 12345
});

How would I query for POSTS that contain RESPONSES that match a certain QUESTION _id. 我将如何查询包含符合一定的问题 _id是回应 帖子 For example: 12345? 例如:12345?

Thanks for the help! 谢谢您的帮助!

I believe this is the query you are looking for 我相信这是您要查找的查询

const _id = 'some object id'
Post.find({ 'responses.question._id' : _id }).then((posts) => {
   console.log(posts);
}).catch((err) => console.log(err))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM