【问题标题】:Mongoose Array Push FailsMongoose 阵列推送失败
【发布时间】:2015-10-03 19:18:10
【问题描述】:

我有一个 Mongoose 架构,其中包含一组对象,如下所示:

multipleThings: [{
    field1: String,
    field2: String,
    field3: String,
    thingId  : { type: ObjectId, default: ObjectId }
}]

在我的代码中,我执行.findOne,它返回我的对象​​。 myObject.multipleThings 在这一点上是 Array[0]。我只是想向这个数组推送一些东西,所以我这样做了

myObject.multipleThings.push(anObjectICreated)

我得到了

undefined 不是函数

在 DocumentArray.SchemaType.applySetters (.../node_modules/mongoose/lib/schematype.js:570:26)

在 Array.MongooseArray.mixin.push (.../node_modules/mongoose/lib/types/array.js:292:27)

在 {The location of .push above in my code}

我不明白是什么阻止我推送到数组?

【问题讨论】:

  • 你能发布架构定义吗?

标签: javascript arrays node.js mongodb mongoose


【解决方案1】:

我还是新手,我建议你试试myObject.multipleThings[0].push(anObjectICreated)

【讨论】:

    猜你喜欢
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    相关资源
    最近更新 更多