问题
Using another website, i would like to know how many documents match a query in my meteor application (through an api call of some sort?). What is the best way to achieve this?
回答1:
The simplest way to do so is to add item to WebApp stack, for example:
WebApp.connectHandlers.stack.splice (0, 0, {
route: '/api/path',
handle: function(req, res, next) {
var count = Documents.find({}).count();
res.writeHead(200, {
'Content-Type': 'application/json',
});
res.write(JSON.stringify({count: count}));
res.end();
},
});
Notice that this code is for Meteor 0.6.5.
来源:https://stackoverflow.com/questions/18499625/how-do-i-setup-an-api-to-access-my-meteor-collection