I'm using MongoDB 2.0.6 with node.js and the mongodb-native module. I'm trying to create a database of different social media items and currently have tweets properly populating my database. I'd like to add a function that gets the most recent tweet ID (not mongo ID but a field called 'api_id') and returns it for use in an API call.
I followed this great tutorial as the base for what I have but the findOne function seems to never hit its callback. I tried using findOne with the native Mongo ID serialization as well but no luck. I'm going to try a workaround suggested here for Mongo 1 but I don't think it will work. Any help would be appreciated.
// Find one by given criteria
updateSocial.prototype.findByCrit = function(crit, callback) {
this.getCollection(function(error, social_collection) {
if( error ) callback(error)
else {
social_collection.findOne({api_type: crit}, function(error, result) {
if( error )
callback(error)
else {
callback(null, result);
}
});
}
});
};
Seems to be working now. Problem must have been elsewhere.