Skip to content

Instantly share code, notes, and snippets.

@aaronshaf
Created November 16, 2012 21:07
Show Gist options
  • Save aaronshaf/4090914 to your computer and use it in GitHub Desktop.
Save aaronshaf/4090914 to your computer and use it in GitHub Desktop.
var Products = {
recent: function() {
var deferred = $.Deferred();
config.mongo.connection.collection('products',function(error, collection) {
collection.find().sort({'modified':-1}).limit(20).toArray(function(err, products) {
if(err)
deferred.fail(err);
else
deferred.resolve(products);
});
});
return deferred;
},
findOne: function(_id) {
var deferred = $.Deferred();
config.mongo.connection.collection('products',function(error, collection) {
collection.findOne({_id:ObjectID(_id)},function(err, product) {
if(err)
deferred.fail(err);
else
deferred.resolve(product);
});
});
return deferred;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment