【问题标题】:Query Mongoose model not of a particular field type查询不属于特定字段类型的 Mongoose 模型
【发布时间】:2021-04-30 08:04:11
【问题描述】:

我想使用 mongoose 查询类型不是数组类型的模型。我不得不将我的模型(lastSeen)的一个字段从日期类型更改为日期数组。我现在需要查询仍然以 lastSeen 为日期的以前的文档。我可以轻松地进行“日期”类型的查询,但是如何查询不是数组类型的字段?

const users = await User.find({lastSeen: {$type: "date", $exists: true}});

请注意,上面的查询会返回类型为日期数组和日期数组的文档

【问题讨论】:

    标签: node.js database express mongoose


    【解决方案1】:

    你可以使用$not

    const users = await User.find({lastseen:{$not:{$type:"array"}}})
    

    【讨论】:

      猜你喜欢
      • 2021-04-27
      • 2015-10-16
      • 2021-09-30
      • 2017-04-28
      • 1970-01-01
      • 2013-12-10
      • 2016-01-08
      • 2021-07-26
      • 2013-10-23
      相关资源
      最近更新 更多