简体   繁体   中英

Mongoose Array Push Fails

I have a Mongoose schema with, among other things, an array of objects like so:

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

In my code I do a .findOne , which returns my object. myObject.multipleThings is an Array[0] at this point. I simply want to push something to this array, so I do

myObject.multipleThings.push(anObjectICreated)

And I get

undefined is not a function

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

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

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

I don't understand what is stopping me from being able to push to the array?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM