node.js - Unable to insert into subdocument -
i have following schema
var childschema = new schema({ name: string, value: string }); var parentschema = new schema({ children: [childschema] });
now, wish insert entries parent.children.
i did following:
parentrecord.children.push({ name:"foo", value: "bar" });
when use console.log, can see here record has been added parent record's children property. has been give id.
now, attempt save record:
parentrecord.save(mycallback);
while save success, see entry not added children property.
- i tried use
parentrecord.markmodified("children");
not help - i have ensured declare
childschema
before declareparentschema
.
i @ wits end trying figure out what's wrong. have set debug property of mongoose true. can see it's identifying new entry can't see getting saved in database.
following output debug messages:
mongoose: parentrecord.update({ _id: objectid("5551895182d9adbe1da34d6a") }) { '$inc': { __v: 1 }, '$set': { anotherfield: 'anothervalue' }, '$pushall': { fields: [ { _id: objectid("55518c682a0744dc20f1473b"), value: 'bar', name: 'foo' } ] } } {}
any hints on else need entry save?
i using mongoose 3.8.12
from can tell change log looks issue resolved in version 3.8.13. may want try upgrading.
Comments
Post a Comment