【问题标题】:Mongo/Mongoose - Count of empty double nested arraysMongo/Mongoose - 空双嵌套数组的计数
【发布时间】:2017-02-09 06:26:10
【问题描述】:

我有以下猫鼬模式:

var RowSchema = new Schema({
  value: String,
  createdAt:{
    type: Date,
    'default': Date.now
  }
});

var ColumnSchema = new Schema({
  rows: [RowSchema],
  createdAt:{
    type: Date,
    'default': Date.now
  }
});

var ItemSchema = new Schema({
  _id: {
    type: String,
    unique: true,
    'default': shortid.generate
  },
  name: String,
  columns: [ColumnSchema],
  createdAt:{
    type: Date,
    'default': Date.now
  }
})

我想运行一个查询来查找在 all 列中包含零行的所有 Item。所以我知道如何找到一个空的数组:

Item.find({ columns: { $exists: true, $eq: [] } })

但我想要类似的东西

Item.find({ 'columns.rows': { $exists: true, $eq: [] } })

【问题讨论】:

    标签: node.js mongodb mongoose aggregation-framework


    【解决方案1】:

    试试

    Item.find({ 'columns.rows': {$in: [] } })
    

    【讨论】:

      猜你喜欢
      • 2017-01-05
      • 2019-12-04
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      • 2015-03-26
      • 2017-01-24
      相关资源
      最近更新 更多