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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -