I have tried aggregate (sakulstra:aggregate) method inside my publish method for making my result set in alphabet order using collation, but got an error on subscription.
Error: Publish function can only return a Cursor or an array of Cursors
I have tried aggregate (sakulstra:aggregate) method inside my publish method for making my result set in alphabet order using collation, but got an error on subscription.
Error: Publish function can only return a Cursor or an array of Cursors
As the error says, a publication can only return Cursorâs - the aggregate function (including when patched by sakulstra:aggregate) returns an array of values.
It is possible to return arbitrary data using the publication system, but itâs not obvious to do, and you are responsible for re-running whatever query (in your case the aggregation) that provides the data: https://docs.meteor.com/api/pubsub.html
Essentially, aggregations are non-reactive. There have been a couple of attempts at making reactive aggregations - and depending on what the aggregation is, they can work quite well, for example: https://github.com/robfallows/tunguska-reactive-aggregate
I have tried this package , and getting an error only, i think this package is not stable
error details:-
tunguska:reactive-aggregate [Error]
Letâs see the code you used, please.
Meteor.publish(âdTypesâ, () => {
return ReactiveAggregate(this, DTypes, [{$match:{name:âBagâ}}], {});
});
//subscribe
Meteor.subscribe(âdTypesâ);
Without any other information, there are clearly two differences between what youâve got and whatâs required:
=>
) in a publication. You must use function
.return ReactiveAggregate
.Take a look at the basic example in the README.
Meteor.publish('dTypes', function() {
ReactiveAggregate(this, DTypes, [{$match:{name:"Bag"}}], {});
});
thank you @robfallows code changed and now got an another error
error: ReactiveAggregate support for Mongo.ObjectID is disabled due to 1 package error
in my collections i am using type string for _id not ObjectId
At the time the publication is instantiated, the package doesnât know how youâve organised your _id
s. So all that message is saying is that âif your collection(s) use ObjectID
s, you have missing dependencies which you need to fix before you can get ObjectID
support.â
Itâs a diagnostic message and shouldnât affect you if you only have string _id
s.
You should have got more information than you have posted above, which explains the missing package(s) you would need to install.
here is the complete error log
I20200721-17:13:55.983(5.5)? ReactiveAggregate support for Mongo.ObjectID is disabled due to 1 package error(s):
I20200721-17:13:55.984(5.5)? 1 - simpl-schema: MODULE_NOT_FOUND
I20200721-17:13:56.410(5.5)? Exception from sub dTypes id CCCGEtkwJvuJYL3i7 Error: A pipeline stage specification object must contain exactly one field.
I20200721-17:13:56.411(5.5)? at update (packages/tunguska:reactive-aggregate/aggregate.js:252:13)
I20200721-17:13:56.411(5.5)? at ReactiveAggregate (packages/tunguska:reactive-aggregate/aggregate.js:319:3)
I20200721-17:13:56.411(5.5)? at Subscription. (imports/api/deliveryTypes.js:30:9)
I20200721-17:13:56.412(5.5)? at packages/matb33_collection-hooks.js:307:21
I20200721-17:13:56.412(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200721-17:13:56.412(5.5)? at Subscription._handler (packages/matb33_collection-hooks.js:306:28)
I20200721-17:13:56.413(5.5)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1771:12)
I20200721-17:13:56.413(5.5)? at packages/ddp-server/livedata_server.js:1046:15
I20200721-17:13:56.413(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200721-17:13:56.414(5.5)? at Subscription._runHandler (packages/ddp-server/livedata_server.js:1044:51)
I20200721-17:13:56.415(5.5)? at Subscription.subscriptionProto._runHandler (packages/mdg:meteor-apm-agent/lib/hijack/wrap_subscription.js:12:24)
I20200721-17:13:56.429(5.5)? at Session._startSubscription (packages/ddp-server/livedata_server.js:860:9)
I20200721-17:13:56.429(5.5)? at Session.sub (packages/ddp-server/livedata_server.js:625:12)
I20200721-17:13:56.429(5.5)? at packages/mdg:meteor-apm-agent/lib/hijack/wrap_session.js:77:34
I20200721-17:13:56.429(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200721-17:13:56.429(5.5)? at Session.sessionProto.protocol_handlers.sub (packages/mdg:meteor-apm-agent/lib/hijack/wrap_session.js:76:44)
I20200721-17:13:56.430(5.5)? Sanitized and reported to the client as: errorClass [Error]: tunguska:reactive-aggregate [Error]
I20200721-17:13:56.431(5.5)? at errorClass. (packages/tunguska:reactive-aggregate/aggregate.js:32:27)
I20200721-17:13:56.431(5.5)? at new errorClass (packages/meteor.js:655:17)
I20200721-17:13:56.431(5.5)? at update (packages/tunguska:reactive-aggregate/aggregate.js:252:13)
I20200721-17:13:56.432(5.5)? at ReactiveAggregate (packages/tunguska:reactive-aggregate/aggregate.js:319:3)
I20200721-17:13:56.432(5.5)? at Subscription. (imports/api/deliveryTypes.js:30:9)
I20200721-17:13:56.432(5.5)? at packages/matb33_collection-hooks.js:307:21
I20200721-17:13:56.439(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200721-17:13:56.440(5.5)? at Subscription._handler (packages/matb33_collection-hooks.js:306:28)
I20200721-17:13:56.440(5.5)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1771:12)
I20200721-17:13:56.440(5.5)? at packages/ddp-server/livedata_server.js:1046:15
I20200721-17:13:56.441(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200721-17:13:56.441(5.5)? at Subscription._runHandler (packages/ddp-server/livedata_server.js:1044:51)
I20200721-17:13:56.441(5.5)? at Subscription.subscriptionProto._runHandler (packages/mdg:meteor-apm-agent/lib/hijack/wrap_subscription.js:12:24)
I20200721-17:13:56.441(5.5)? at Session._startSubscription (packages/ddp-server/livedata_server.js:860:9)
I20200721-17:13:56.442(5.5)? at Session.sub (packages/ddp-server/livedata_server.js:625:12)
I20200721-17:13:56.442(5.5)? at packages/mdg:meteor-apm-agent/lib/hijack/wrap_session.js:77:34 {
I20200721-17:13:56.442(5.5)? isClientSafe: true,
I20200721-17:13:56.442(5.5)? error: âErrorâ,
I20200721-17:13:56.443(5.5)? reason: âtunguska:reactive-aggregateâ,
I20200721-17:13:56.443(5.5)? details: undefined,
I20200721-17:13:56.443(5.5)? message: âtunguska:reactive-aggregate [Error]â,
I20200721-17:13:56.443(5.5)? errorType: âMeteor.Errorâ
I20200721-17:13:56.443(5.5)? }
I20200721-17:13:56.444(5.5)?
I20200721-17:13:56.816(5.5)? Exception from sub dTypes id sFwuYhBeh3Kd6nwTe Error: A pipeline stage specification object must contain exactly one field.
I20200721-17:13:56.818(5.5)? at update (packages/tunguska:reactive-aggregate/aggregate.js:252:13)
I20200721-17:13:56.822(5.5)? at ReactiveAggregate (packages/tunguska:reactive-aggregate/aggregate.js:319:3)
I20200721-17:13:56.823(5.5)? at Subscription. (imports/api/deliveryTypes.js:30:9)
I20200721-17:13:56.823(5.5)? at packages/matb33_collection-hooks.js:307:21
I20200721-17:13:56.823(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200721-17:13:56.823(5.5)? at Subscription._handler (packages/matb33_collection-hooks.js:306:28)
I20200721-17:13:56.823(5.5)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1771:12)
I20200721-17:13:56.824(5.5)? at packages/ddp-server/livedata_server.js:1046:15
I20200721-17:13:56.824(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200721-17:13:56.824(5.5)? at Subscription._runHandler (packages/ddp-server/livedata_server.js:1044:51)
I20200721-17:13:56.824(5.5)? at Subscription.subscriptionProto._runHandler (packages/mdg:meteor-apm-agent/lib/hijack/wrap_subscription.js:12:24)
I20200721-17:13:56.825(5.5)? at Session._startSubscription (packages/ddp-server/livedata_server.js:860:9)
I20200721-17:13:56.825(5.5)? at Session.sub (packages/ddp-server/livedata_server.js:625:12)
I20200721-17:13:56.825(5.5)? at packages/mdg:meteor-apm-agent/lib/hijack/wrap_session.js:77:34
I20200721-17:13:56.825(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200721-17:13:56.825(5.5)? at Session.sessionProto.protocol_handlers.sub (packages/mdg:meteor-apm-agent/lib/hijack/wrap_session.js:76:44)
I20200721-17:13:56.826(5.5)? Sanitized and reported to the client as: errorClass [Error]: tunguska:reactive-aggregate [Error]
I20200721-17:13:56.827(5.5)? at errorClass. (packages/tunguska:reactive-aggregate/aggregate.js:32:27)
I20200721-17:13:56.827(5.5)? at new errorClass (packages/meteor.js:655:17)
I20200721-17:13:56.827(5.5)? at update (packages/tunguska:reactive-aggregate/aggregate.js:252:13)
I20200721-17:13:56.827(5.5)? at ReactiveAggregate (packages/tunguska:reactive-aggregate/aggregate.js:319:3)
I20200721-17:13:56.828(5.5)? at Subscription. (imports/api/deliveryTypes.js:30:9)
I20200721-17:13:56.828(5.5)? at packages/matb33_collection-hooks.js:307:21
I20200721-17:13:56.828(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200721-17:13:56.828(5.5)? at Subscription._handler (packages/matb33_collection-hooks.js:306:28)
I20200721-17:13:56.829(5.5)? at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1771:12)
I20200721-17:13:56.829(5.5)? at packages/ddp-server/livedata_server.js:1046:15
I20200721-17:13:56.829(5.5)? at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1234:12)
I20200721-17:13:56.829(5.5)? at Subscription._runHandler (packages/ddp-server/livedata_server.js:1044:51)
I20200721-17:13:56.830(5.5)? at Subscription.subscriptionProto._runHandler (packages/mdg:meteor-apm-agent/lib/hijack/wrap_subscription.js:12:24)
I20200721-17:13:56.830(5.5)? at Session._startSubscription (packages/ddp-server/livedata_server.js:860:9)
I20200721-17:13:56.830(5.5)? at Session.sub (packages/ddp-server/livedata_server.js:625:12)
I20200721-17:13:56.830(5.5)? at packages/mdg:meteor-apm-agent/lib/hijack/wrap_session.js:77:34 {
I20200721-17:13:56.830(5.5)? isClientSafe: true,
I20200721-17:13:56.831(5.5)? error: âErrorâ,
I20200721-17:13:56.831(5.5)? reason: âtunguska:reactive-aggregateâ,
I20200721-17:13:56.831(5.5)? details: undefined,
I20200721-17:13:56.831(5.5)? message: âtunguska:reactive-aggregate [Error]â,
I20200721-17:13:56.832(5.5)? errorType: âMeteor.Errorâ
I20200721-17:13:56.837(5.5)? }
I20200721-17:13:55.983(5.5)? ReactiveAggregate support for Mongo.ObjectID is disabled due to 1 package error(s):
I20200721-17:13:55.984(5.5)? 1 - simpl-schema: MODULE_NOT_FOUND
Thatâs the warning - itâs not an error.
I20200721-17:13:56.410(5.5)? Exception from sub dTypes id CCCGEtkwJvuJYL3i7 Error: A pipeline stage specification object must contain exactly one field.
Thatâs the error from the MongoDB library and itâs basically saying your pipeline is incorrect. To my eye your pipeline looks ok, except for the âsmart quotesâ: âBagâ
vs "Bag"
. Is that your actual pipeline?
Thank you very much @robfallows issue fixed, i have installed package simpl-schema and everything is working fine now.
Thank you so much! Itâs very helpful to me.
@robfallows i faced an issue when deploy the changes to galaxy,the issue is app is being very slow and some functions like sync is not working , so i reverted my changes( unistall tunguska:reactive-aggregate and simpl-schema 1.9.0 and my publications changed to previous state) and the issue is solved. do you have any idea why this happening?
i posted this issue as another post, please check. Thank you.
Just like I said in the reply you quote: if your Meteor hasnât been updated you would be using an older version of Node. Galaxy uses the latest one, hence why you get the warning there but not locally. Hereâs the relevant command to update Meteor: https://docs.meteor.com/commandline.html#meteorupdate
Most issues to do with poor aggregation performance are down to missing or bad indexes, especially with large collections. I would suggest using the debug
parameter to look at what the aggregation is doing. Something like:
ReactiveAggregate(this, collection, pipeline, {
debug(explain) {
console.log(JSON.stringify(explain, null, 2));
}
});
Refer to the official MongoDB driver doc for more information.
Thank you will check this.
I20200721-17:13:55.983(5.5)? ReactiveAggregate support for Mongo.ObjectID is disabled due to 1 package error(s): I20200721-17:13:55.984(5.5)? 1 - simpl-schema: MODULE_NOT_FOUND
Hi @robfallows , how can I remove this warning (without installing simpl-schema package since Iâm not using it):
I20200721-17:13:55.983(5.5)? ReactiveAggregate support for Mongo.ObjectID is disabled due to 1 package error(s):
I20200721-17:13:55.984(5.5)? 1 - simpl-schema: MODULE_NOT_FOUND
how can I remove this warning (without installing simpl-schema package since Iâm not using it):
In short, you canât suppress warnings. However, it sounds like a good idea. Please raise a GitHub issue so it can be tracked. Thanks