I’m getting error saying Exception from sub attachments id TvCprHujzARzH92vg Error: Publish function can only return a Cursor or an array of Cursors
but what I see in my terminal is this is returning the FileCursor.
Here is the server side for publication
Meteor.publish('attachments', function (uuid) {
check(uuid, Match.OneOf(String, null, undefined));
if (!uuid) return this.ready();
console.log('uuid - pub', uuid);
console.log(
'UserFiles.findOne(uuid),',
UserFiles.findOne(uuid),
);
return UserFiles.findOne({_id: uuid});
});
console.log(
'UserFiles.findOne(uuid),',
UserFiles.findOne(uuid),
);
This shows
FileCursor {
_fileRef: {
_id: 'ecjkKo6k5pE9MiH36',
name: 'mikhail-vasilyev-gGC63oug3iY-unsplash.jpg',
extension: 'jpg',
ext: 'jpg',
...
...
...
}
}
I don’t know if this matters but this returns the FileCursor
not regular Cursor
Also, findOne()
return a document
but here I’m getting FileCursor
and console.log('uuid - pub', uuid)
shows ecjkKo6k5pE9MiH36
This is the client side.
const ready = useTracker(
() => Meteor.subscribe('attachments', uuid).ready(),
[uuid],
);
Attempts
Created a variable and returned that variable
Meteor.publish('attachments', function (uuid) {
check(uuid, Match.OneOf(String, null, undefined));
if (!uuid) return this.ready();
const file = UserFiles.findOne({_id: uuid});
return file;
});
Also, I tried to console UserFiles.find({_id: uuid})
and the output looks like this
FilesCursor {
_collection: <ref *1> FilesCollection {
_events: Events <[Object: null prototype] {}> {
_handleUpload: [EE],
_finishUpload: [EE]
},
_eventsCount: 2,
debug: false,
schema: {
_id: [Object],
size: [Object],
...
...
...
}
It looks a little wried…
and returned that UserFiles.find({_id: uuid});
in publication, but I’m getting the same error
but this didn’t work. Is there any way I should try?