【问题标题】:How to find a record based on id in an array in mongoose如何在猫鼬的数组中根据id查找记录
【发布时间】:2017-01-05 20:53:56
【问题描述】:

我正在尝试根据数组中存在的 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) {});

但是在我有记录之前我变得空虚了。任何人都可以建议帮助。谢谢。

【问题讨论】:

  • 你能告诉我你的Employeehierarchy Schema吗?
  • 嗨拉维,当然.....

标签: node.js mongodb mongoose meanjs


【解决方案1】:

试试这个:

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

【讨论】:

    猜你喜欢
    • 2020-09-12
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    • 2017-03-28
    • 1970-01-01
    • 2014-03-10
    • 2016-10-02
    • 1970-01-01
    相关资源
    最近更新 更多