SimpleSchema 和 MongoDB 数组中的嵌套数组

SimpleSchema and MongoDB Nested Arrays in Arrays

我正在使用 SimpleSchema 和 Meteor 来构建数据库条目。

问题是,我有一个对象数组(这些数据显示在 HTML table 中)并且需要更新单个单元格。

我的架构如下所示:(Coffeescript)

drags:
    type: [[Object]]
    label: "The correct assignment of drop values"
    optional: true
    blackbox: true
"drags.$":
    type: [Object]
    label: "Row of the Table"
    blackbox: true
"drags.$.$":
    type: Object
    label: "Cell of the Table"
"drags.$.$._id":
    type: String
    label: "Unique Id of Draggable"
    optional: true
"drags.$.$.text":
    type: String
    label: "Text of Draggable"
    optional: true
"drags.$.$.fixed":
    type: Boolean
    label: "Is this Draggable Fixed to the correct spot"
    optional: true
"drags.$.$.color":
    type: String
    label: "Color of Draggable"
    optional: true

我更新特定单元格的数据库调用是:

db.update({_id:"some-id"},{$set: {"drags.1.2.fixed":true}})

此调用引发此错误:

Error: When the modifier option is true, validation object must have at least one operator

使用 simple-schema 几乎总是更容易分别为每个层定义架构并将它们嵌套。你的情况:

drags: 
  type: [row]
  label: "The correct assignment of drop values"
  optional: true
  blackbox: true

row:
  type: [cell]

然后定义您的单元格属性。通常,如果您将对象定义为 blackbox,则没有必要定义其各个属性。您在单元格级别有一个必填字段,但在该字段之上您说它是黑框。