如何通过嵌套id查询mongoose

时间:2017-06-14 07:33:49

标签: node.js mongodb express mongoose mongoose-schema

我有一个"关注"这样的架构:

var Follow = mongoose.model('Follow', new mongoose.Schema({
personWhoFollow_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'user'
},
personWhoIsFollowed_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'user'
}}));

我用params id的用户请求时所做的查询就像:

Follow.findOne({personWhoFollow_id: req.params.id}, function(err, follow){});

它不起作用!我尝试了console.log(跟随),我收到了这个错误:

  

施放到ObjectId的值失败" favicon.ico"在路径" personWhoFollow_id"对于模型"关注"'和一些长对象

0 个答案:

没有答案