Created
October 19, 2010 18:20
-
-
Save sivy/634725 to your computer and use it in GitHub Desktop.
issue with collection.update callback params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
update stats for the URL | |
*/ | |
hit_emitter.on('newHit', function(url, hit){ | |
var data = { "$push": { "stats.hits": hit }, "$inc": { "stats.hitcounter": 1 } } | |
urlProvider.update(url, data, function(error, url){ | |
console.log('updated hit: ' + JSON.stringify(url)); | |
}); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
null | |
{ '$push': | |
{ 'stats.hits': | |
{ created_on: Tue, 19 Oct 2010 18:12:58 GMT | |
, referer: 'http://localhost:3000/' | |
} | |
} | |
, '$inc': { 'stats.hitcounter': 1 } | |
, modified_on: Tue, 19 Oct 2010 18:12:58 GMT | |
} | |
updated hit: {"$push":{"stats.hits":{"created_on":"2010-10-19T18:12:58.684Z","referer":"http://localhost:3000/"}},"$inc":{"stats.hitcounter":1},"modified_on":"2010-10-19T18:12:58.686Z"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UrlProvider.prototype.update = function(url, data, callback) { | |
this.getCollection(function(error, urls_collection) { | |
if( error ) { | |
callback(error); | |
} else { | |
data.modified_on = new Date(); | |
console.log('updating url with ' + sys.inspect(data)); | |
urls_collection.update( | |
{ _id:url._id }, | |
data, | |
function(error, url) { | |
console.log(sys.inspect(error)); | |
console.log(sys.inspect(url)); // url is actually == data | |
if (error) { | |
console.log(error.message) | |
callback(error) | |
} else { | |
callback(null, url); | |
} | |
}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment