javascript - How do I add value to MongooseJS array on creation -
i have city
schema looks this:
... name: string, reviews: [{ user: string, text: string }], ...
and create new city
using:
var city = new city({ name: "london", reviews: {user: "test user", text: "this review"} }); city.save(function(err){ //check err //do stuff });
but i'm getting error:
casterror: cast array failed value "[object object]"
what doing wrong?
you passing object in place of array in reviews. pass as
var city = new city({ name: "london", reviews: [{user: "test user", text: "this review"}] });
Comments
Post a Comment