Hi
Ok so the code for the save function looks like this
Collection.prototype.save = function(doc, options, callback) {
var args = Array.prototype.slice.call(arguments, 1);
callback = args.pop();
options = args.length ? args.shift() : null;
var id = (doc instanceof OrderedHash) ? doc.get('_id') : doc['_id'];
if(id != null) {
this.update({'_id':id}, doc, {upsert: true, safe: options !=
null ? options.safe : false}, callback);
} else {
this.insert(doc, function(err, docs) { Array.isArray(docs) ?
callback(err, docs[0]) : callback(err, docs); });
}
};
as you see it's an update call for the save only if the _id attribute
exists on the document which it does on yours. However if it's not a
ObjectID instance it won't work as the bson serializer will fail.
So do something like this
var ObjectID = require('mongodb').ObjectID,
sys = require('sys');
sys.puts("====================== " + (yourdoc._id instanceof
ObjectID));
it should be true for it to work.
Are you doing a toJson on the original doc changing it and then saving
it using save ?
in that case you have to ensure that you create a ObjectID object
around the _id hex value as
toJson converts the ObjectID object to a hex representation.
yourdoc._id = new ObjectID(yourdoc._id)
Cheers
Christian
On Aug 5, 11:42 am,
rick.wa...@gmail.com wrote:
> Ok....
>
> So in the database I have:
>
> {"n":"me","created_at":"2010-08-05T08:49:44.135Z","_id":"4c5a7b28d7e1612108 000001"}
>
> After I execute the code (node app.js) I see:
>
> found!
>
> {"n":"me","created_at":"2010-08-05T08:49:44.135Z","_id":"4c5a7b28d7e1612108 000001"}
>
> saved...
>
> Next I look in the database and see that the data is unchanged :(
>
> Here is the code:
>
> So I have a helper class called DataProvider: The code for this is here:
http://pastie.org/1077010
>
> I construct an instance of this:
>
> var myCollection = new DataProvider(host,port,"core", "collection");
>
> myCollection.findById("4c5a7b28d7e1612108000001", function(error, result){
>
> if(error) {
> require('sys').debug("error!");
> } else if (result) {
>
> require('sys').debug("found!");
>
> require('sys').debug(JSON.stringify(result));
> result.newField="data";
> myCollection.save(result,function(error,result) {
>
> });
> }
>
>
>
> })