Reputation: 2837
I'm trying to use rawCollection in a Meteor 1.8.1 publish function, based on the example here. Instead of returning the distinct values, I want to return a regular cursor containing all my documents. This is so I can later use collation to implement a case-insensitive sort.
However when I subscribe to the publication below, I get the following error:
Publish function can only return a Cursor or an array of Cursors
But the console log in the server prints out the following:
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:
...
So, it appears that my code is producing a Cursor, but the publish function doesn't like it.
Here's my code:
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;
});
Any idea what I'm doing wrong? Thank you!
Upvotes: 4
Views: 1643
Reputation: 44
I think this code will do the job
Meteor.publish('mycollection', async function() {
const result = await MyCollection.rawCollection().find({});
console.log('result', result.fetch());
return result;
});
Hope it will help :)
Upvotes: -1