【问题标题】:mongoose find collections that does not have a empty array猫鼬查找没有空数组的集合
【发布时间】:2021-09-03 15:02:11
【问题描述】:

例如,我的猫鼬系列看起来像这样

{
 _id: 1,
 arr: []
},
{
 _id: 2,
 arr: [2]
}

我想获取所有没有arr 的集合作为一个空数组,如何?

【问题讨论】:

    标签: javascript database mongoose


    【解决方案1】:

    您可以使用$not: {$size: 0}

    db.doc.find({ arr: { $exists: true, $not: {$size: 0} } })
    

    【讨论】:

      猜你喜欢
      • 2020-06-03
      • 2020-03-28
      • 2020-12-01
      • 2017-03-30
      • 1970-01-01
      • 2020-09-12
      • 2017-04-03
      • 1970-01-01
      • 2021-05-06
      相关资源
      最近更新 更多