【问题标题】:mongodb query with mongoose in any Objectid在任何 Objectid 中使用 mongoose 进行 mongodb 查询
【发布时间】:2015-03-13 19:35:51
【问题描述】:

我有一个架构如下

var S = new Schems({
  f : Mixed
})

mongoose.model('collection', S);

如何查询“集合”,以便找到 f 是 ANY mongo ObjectId 的文档?

例如如果'

collection' = [{ f: ObjectId('549138f19f52f268c717a8a2'), _id : 1 },
{ f : ObjectId('549139129f52f268c717a8a4'), _id : 2 }, { f : false, _id :3  }  ]

结果应该有 _id 1 和 2

【问题讨论】:

    标签: node.js mongodb mongoose mongodb-query


    【解决方案1】:

    您要求$type 运算符。 ObjectId 类型为“7”类型:

    Collection.find({ "f": { "$type": 7 } },function(err,docs) {
       // results in here
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 2015-02-10
      相关资源
      最近更新 更多