如何在Meteor发布功能中使用rawCollection

问题描述 投票:1回答:1

基于示例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: 
...

所以,看来我的代码正在产生一个游标,但是发布函数不喜欢它。

这是我的代码:

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;
});

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

mongodb meteor publish
1个回答
0
投票

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

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

希望它会有所帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.