Node.js 如何在mongoose中基于数组中的id查找记录

Node.js 如何在mongoose中基于数组中的id查找记录,node.js,mongodb,mongoose,meanjs,Node.js,Mongodb,Mongoose,Meanjs,我试图根据数组中存在的id获取记录,但不幸的是查询失败 我的模式 var EmployeehierarchySchema = new Schema({ created_by: { type: Schema.ObjectId, ref: 'Employee' }, parents: { type: Array, default: '' }, childrens: { type: Array, default: '' },

我试图根据数组中存在的id获取记录,但不幸的是查询失败 我的模式

 var EmployeehierarchySchema = new Schema({

  created_by: {
    type: Schema.ObjectId,
    ref: 'Employee'
  },
  parents: {
    type: Array,
    default: ''
  },
  childrens: {
    type: Array,
    default: ''
  },
});
 "parents" : [ 
    ObjectId("586e3bc35f01e338d7341304")
]
我想根据id获取这个记录,我编写了以下代码

 var item = {'parents':req.id};
      Employeehierarchy.find(item).exec(function (err, employeehierarchy) {});
但是在我有记录的时候我已经空了。有人能建议帮忙吗。Yhanks。

试试这个:

 Employeehierarchy.find({'parents':{$in:[req.id]}).exec(function (err, employeehierarchy) {});

你能给我看看你的
Employeehierarchy
Schema吗?嗨,拉维,当然。。。。。