A subset of mongoose query subsets

  mongodb, question

First of all, my mongoose models are as follows:

var clubsSchema = new mongoose.Schema({
 "clubCreatetime": String,
 "clubCreater": String,
 "clubName": String,
 "clubDescription": String,
 "clubImage": String,
 "clubMenbers": [String],
 "clubTopics": [{
 "topicCreatetime": String,
 "topicCreater": String,
 "topicTitle": String,
 "topicContent": String,
 "topicComment": [{
 "userId": String,
 "userName": String,
 "commentCreatetime": String,
 "commentContent": String
 }],
 "topicLike": [String],
 "topicState": String
 }],
 "clubState": String
 })

Then, my code is as follows:

let orgId = req.param("orgId");
 let topicId = req.param("topicId");
 Club.findOne({
 _id: orgId
 }, function(clubErr, clubDoc){
 //console.log(clubDoc);
 if(clubErr){
 res.json({
 status: '1',
 msg: clubErr.message,
 Result:' Failed to find the club!'
 })
 } else {
 clubDoc.clubTopics.findOne({
 _id: topicId
 }, function(topicErr, topicDoc){
 console.log(topicDoc);
 if(topicErr){
 res.json({
 status: '1',
 msg: topicErr.message,
 Result:' Failed to find the topic!'
 })
 } else {
 res.json({
 status:'0',
 Msg:' Success in finding this topic!'  ,
 result: topicDoc
 })
 }
 })
 }
 })

Here, I want to find the community first through the community Id in the route. Then, according to the topic Id in the route, the whole content of the topic is queried. However, it reminds me that the method of. findOne () does not exist, so if I want to ask for advice, I will query the topic under the community according to my id. How do I write it? Thank you!

At present, the method of returning topic information is as follows:

for(let i=0;   i<clubDoc.clubTopics.length;  i++){
 if(clubDoc.clubTopics[i]._id==topicId){
 console.log(clubDoc.clubTopics[i]);
 }
 }

Would you like to ask mongoose if there is a more direct way? ? ?

You can build a model for clubTopics, with id stored in the community and ref pointing to the clubTopics collection, which is populate when querying.
http://mongoosejs.com/docs/po …