marcello3d / node-mongolian

[project inactive] Mongolian DeadBeef is an awesome Mongo DB driver for node.js
https://groups.google.com/group/node-mongolian
zlib License
350 stars 50 forks source link

update n00b how-to #55

Closed ghost closed 13 years ago

ghost commented 13 years ago

I am trying to update a record by the primary key. (I got insert and find working great, thank you!)

There are no examples or tests of update, save or findAndModify.

My code is, the id exists tabCol.update({_id:'123121231'} ,{ stationName:'ha ha' } ,false,false ,function(err,res) { console.log(res); });

It does not update when I look at mongo and it prints out undefined. There should be an example of how to update by primary key.

2nd question is more mongo: When to use update vs findAndModify vs save, ex when 'updating' by pk.

tia, Vic

marcello3d commented 13 years ago

Vic: did you check your err value? Maybe there was a server error. It's good practice to always check this for errors.

Your best bet for mongo documentation is mongo's website! http://www.mongodb.org/display/DOCS/Manual

ghost commented 13 years ago

OK, now I can update, but not w/ _id. How do I update w/ _id? findAndModify({ query:{roomName:'Bla'} ,update:{ stationName:'ha ha' } },function(err,res) { console.log(err); console.log(res); });

ghost commented 13 years ago

On the first way, it give null for err. I think the second way is good, I just need to figure out why it does not like _id. hint?

ghost commented 13 years ago

OK, I got a clue, findById also does not work, so it might not find a string, might need objectId. I think I can figure it out now!