when query monodb shell, able update document. mongodb command use: db.users.update({name:"bob"}, {$set: {email:"newemail@gmail.com} })
but when try update mongoose, doesn't work. missing??
this code in mongoose:
// create users schema
var userschema = mongoose.schema({ name: string, email: string }, {collection: "users"});
// create model
var usermodel = mongoose.model("usermodel", userschema);
// update document
usermodel.update({name:"bob"}, {$set: {email:"newemail@gmail.com"}} );
you should wait callback see if operation succesful or not
usermodel.update({ name: "bob" }, {$set: { email:"newemail@gmail.com" }}, function (err, user) { if (err) return handleerror(err); res.send(user); });
the mongoose
working asynchronously, should wait response in callback. there synchrone way node
not recommended block stack.
Comments
Post a Comment