向具有其他架构参考的架构进行查询

时间:2019-06-13 03:30:03

标签: mongodb-query

我有一个“用户”模式,该模式引用了其他“注释”模式。我想查询“用户”模式(查询是指“注释”模式)。但是我没有得到任何文件

Blockquote

//用户模式

const serSchema=mongoose.Schema({
    category:{
        required: true,
        type: String,
        maxlength: 20
    },
    comment:[{
        type: Schema.Types.ObjectId,
        ref: 'Comment'
    }]
})
const autoPoplulateComment = function(next) {
    this.populate('comment');
    next();
  };


userSchema.pre('find',autoPoplulateComment);
const User=mongoose.model('User',offerSchema);

//评论计划

const commentSchema=mongoose.Schema({
    name:{
        type: String,
        maxlength: 25
    },
    comment:{
        type: String,
        maxlength: 100
    },
    rating:{
        type: Number
    }
});
const Comment=mongoose.model('Comment',commentSchema);

//节点查询

app.get('/api/comments',(req,res)=>{
    let findArgs={"comment.rating":{$gte: 4} } ;

    User.
    find(findArgs,(err,docs)=>{
        if(err) return res.status(400).send(err);
        res.status(200).send(docs);
    })

输出就像{“ docs”:[]}

0 个答案:

没有答案