mongoose update problem

26 views
Skip to first unread message

xiao qu

unread,
Dec 29, 2014, 2:32:05 AM12/29/14
to nod...@googlegroups.com

First I created the mongoose schema: 

var cardSchema = mongoose.Schema({
  **userId: String,
  imageUrl: String**
})

Then I defined model:

var Card = mongoose.model('Card', cardSchema)

Then I created a new card:

var newCard = new Card({
   **userId: "bablaba"**
});

Then the new card is saved correctly(I tested):

newCard.save(function(err,theCard){
  if(err) return console.log(err);
  console.log("saved");
  console.log(theCard);
  })

Now I need to update information in the card. I want to add/insert imageUrl into the saved new card. Here's a few ways I tried: 

1.

Card.where({ _id: _id }).update({
   $set: {imageUrl:"blablab"}
 });

2.

Card.update(_id,{$set:{imageUrl:"balbalab"}})

3.

Card.update({_id: updateInfo._id}, {note0:updateInfo.note0, note1: updateInfo.note1},{multi:true}, function(err, numberAffected){});

None of these three worked!!! Please help..

Reply all
Reply to author
Forward
0 new messages