如何设置 api 来访问我的流星收藏? [英] How do I setup an api to access my meteor collection?
本文介绍了如何设置 api 来访问我的流星收藏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用另一个网站,我想知道有多少文档与我的流星应用程序中的查询匹配(通过某种 API 调用?).实现这一目标的最佳方法是什么?
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?
推荐答案
最简单的方法是将 item 添加到 WebApp 堆栈中,例如:
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();
},
});
请注意,此代码适用于 Meteor 0.6.5.
Notice that this code is for Meteor 0.6.5.
这篇关于如何设置 api 来访问我的流星收藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文