javascript - Saving Mongoose nested schema -
i'm having issue saving nested subdocs - not sure if because it's not array or - docs seem suggest nested objects auto saved not in case.
a child schema:
var address = new schema({ phone: string, name: string, street: { type: string, required: true } });
main schema:
var order = new schema({ code: { type: string }, address: { type: schema.types.objectid, ref: "address" } });
neither of these work.
create doc doesn't throw errors subdoc not saved
var = new address({ phone: 000 }); var o = new order({ address: }).save();
this gives cast objectid failed error:
var o = new order({ address: { phone: 000 } }).save();
the way seems work saving subdocs first i'd avoid have multiple addresses it's bit messy.
it's weird have never encountered issue - ideas?
ok. evidently cannot use subdocs without array. see post embedded document without array? , bug thread explaining reasoning: https://github.com/learnboost/mongoose/pull/585
Comments
Post a Comment