如何在流星发布功能中使用rawCollection

基于示例here,我试图在Meteor 1.8.1发布功能中使用rawCollection。我想返回一个包含我所有文档的常规游标,而不是返回不同的值。这样一来,以后我就可以使用归类来实现case-insensitive sort

但是,当我订阅下面的出版物时,出现以下错误:

Publish function can only return a Cursor or an array of Cursors

但是服务器中的控制台日志会打印出以下内容:

result Cursor {
I20191107-11:44:26.485(0)?   pool: null,I20191107-11:44:26.485(0)?   server: null,I20191107-11:44:26.485(0)?   disconnectHandler: 
...

因此,看来我的代码正在生成游标,但是publish函数不喜欢它。

这是我的代码:

publications.js:

const raw = MyCollection.rawCollection();
raw.findme = Meteor.wrapAsync(raw.find);

Meteor.publish('mycollection',function() {
    const result = raw.findme({});
    console.log('result',result);
    return result;
});

知道我在做什么错吗?谢谢!

wqf163 回答:如何在流星发布功能中使用rawCollection

我认为这段代码可以完成工作

Meteor.publish('mycollection',async function() {
    const result = await MyCollection.rawCollection().find({});
    console.log('result',result.fetch());
    return result;
});

希望它会有所帮助:)

本文链接:https://www.f2er.com/3145094.html

大家都在问