versolearning / find-from-publication Goto Github PK
View Code? Open in Web Editor NEWEnable finding all documents that have been published by a given publication
Enable finding all documents that have been published by a given publication
findFromPublication works great for me when I use it from within a template but when I try using the observe function on the cursor I don't hit the added code when adding new documents to the db (on initial page load the added function does happen for all items that are already in the collection, but afterwards it doesn't).
// client code
Meteor.subscribe('allPosts', {
onReady: function() {
Posts.findFromPublication('allPosts', {}).observe({
added: function(doc) {
// this line isn't hit when adding new documents
}
});
},
onError: function() {
console.log("error");
}
});
ive followed the instructions on read me but I've got error on client side
MyModel.findFromPublication is not a function
any hints on this problem?
Maybe I am missing something. Here is the use case:
Meteor.users.findFromPublication({'emails.address': email})
will find any user who has a matching email in his emails (array of objects with field address containing the email). It works on the server. In my case it finds one matching user.
But when I call FindFromPublication on the client, it returns 0 objects.
All the other queries with findFromP work but not this one.
I should add that I am calling subscribe with a query and a sort. Not just a simple subscription.
:)
FindFromPublication.publish('host.hostevents', function (username) {
// var userId = this.userId,
let host = Meteor.users.find({username: username});
if(host){
let data = [
Meteor.users.find({username: username,
$or: [
{type: "H"},
{type: "T"},
{type: "O"}
]})
];
if (data) {
return data;
}
}
return this.ready();
});
the subscription above leads to error below,
Exception in template helper: Error: $or/$and/$nor entries need to be full objects
at selectors.map.subSelector (http://localhost:3000/packages/minimongo.js?hash=69b3295a15785e800af1d79e2fca46b6ec29aac0:617:13)
at Array.map (<anonymous>)
at compileArrayOfDocumentSelectors (http://localhost:3000/packages/minimongo.js?hash=69b3295a15785e800af1d79e2fca46b6ec29aac0:615:20)
while a normal meteor.publish doesn't give errors how ever, i get the verlap which is why I am trying to use this package.
What could be wrong?
I am getting a lot of these types of messages on the Meteor server side terminal output.
I20151002-18:48:30.810(0)? Exception from sub recentPosts id K42kw2vAkK5wxawTv Error: Match error: Failed Match.OneOf or Match.Optional validation
I20151002-18:48:30.811(0)? at checkSubtree (packages/check/match.js:244:1)
I20151002-18:48:30.811(0)? at check (packages/check/match.js:32:1)
I20151002-18:48:30.811(0)? at [object Object]._.extend._getFindOptions (packages/mongo/collection.js:244:1)
I20151002-18:48:30.811(0)? at [object Object]._.extend.find (packages/mongo/collection.js:280:1)
I20151002-18:48:30.812(0)? at [object Object].<anonymous> (server/publications.js:459:21)
I20151002-18:48:30.812(0)? at [object Object]._handler (packages/percolate_find-from-publication/packages/percolate_find-from-publication.js:49:1)
I20151002-18:48:30.812(0)? at maybeAuditArgumentChecks (livedata_server.js:1692:12)
I20151002-18:48:30.812(0)? at [object Object]._.extend._runHandler (livedata_server.js:1023:17)
I20151002-18:48:30.813(0)? at [object Object]._.extend._startSubscription (livedata_server.js:842:9)
I20151002-18:48:30.813(0)? at [object Object]._.extend.protocol_handlers.sub (livedata_server.js:614:12)
I20151002-18:48:30.813(0)? Sanitized and reported to the client as: Match failed [400]
How should investigate this problem (if it is a problem)?
Here is the publish function:
FindFromPublication.publish('recentPosts', function (limit) {
var username = getUsername(this.userId);
return Articles.find({
author: username
}, {
sort: {
createdAt: -1
},
limit: limit
});
});
I want to generate report that calculate many collections and then return it like this:
// Server
FindFromPublication.publish('allPosts', function() {
var data = [];
// do something with many collections
return data;
});
// client
Meteor.subscribe('allPosts');
var postsCursor = Posts.findFromPublication('allPosts');
Here is my case:
I am subscribed to my own user from db.users
collection.
Then I am subscribing to the list of users on some page filtered by user id's, i.e. something like:
db.users.find({_id: {$in: ['myuserid', 'otheruserid1', 'otheruserid2', ...]}}, {skip: 10})
after this
db.users.findFromPublication('mysub', {_id: {$in: ['myuserid', 'otheruserid1', 'otheruserid2', ...]}})
always includes my user even though it is not received from mysub
, but is subscribed to separately. When I remove the _id
filter, i.e. doing just
db.users.findFromPublication('mysub', {})
it returns LESS elements (same list excluding me) even though removing a filter is not expected to exclude any results.
With the update I get the following error:
Error: $or/$and/$nor entries need to be full objects meteor.js:1048:11
compileArrayOfDocumentSelectors/<@http://localhost:3000/packages/minimongo.js?hash=04456b5cba2949764c60f0809ae5cf78590bcd67:617:13
compileArrayOfDocumentSelectors@http://localhost:3000/packages/minimongo.js?hash=04456b5cba2949764c60f0809ae5cf78590bcd67:615:10
$and@http://localhost:3000/packages/minimongo.js?hash=04456b5cba2949764c60f0809ae5cf78590bcd67:328:32
compileDocumentSelector/docMatchers<@http://localhost:3000/packages/minimongo.js?hash=04456b5cba2949764c60f0809ae5cf78590bcd67:646:14
compileDocumentSelector@http://localhost:3000/packages/minimongo.js?hash=04456b5cba2949764c60f0809ae5cf78590bcd67:635:23
_compileSelector@http://localhost:3000/packages/minimongo.js?hash=04456b5cba2949764c60f0809ae5cf78590bcd67:4013:12
Matcher@http://localhost:3000/packages/minimongo.js?hash=04456b5cba2949764c60f0809ae5cf78590bcd67:3944:24
Cursor@http://localhost:3000/packages/minimongo.js?hash=04456b5cba2949764c60f0809ae5cf78590bcd67:1430:20
find@http://localhost:3000/packages/minimongo.js?hash=04456b5cba2949764c60f0809ae5cf78590bcd67:2028:12
find@http://localhost:3000/packages/mongo.js?hash=f70e3bfe4cc05b9ab7dc360ca483fa530d45ebc6:425:12
@http://localhost:3000/packages/percolate_find-from-publication.js?hash=8a2ba684b8f9877db688f55ca08218d2a901b192:86:12
Homepage.js/exports.default<@http://localhost:3000/app/app.js?hash=687575af54a94b99c47519790b82a33020be7078:1551:18
Using the following queries:
FindFromPublication.publish('questions.hottest', function() {
var claps = Claps.aggregate([
{ $match: { createdAt: {$gt: new Date((new Date() as any) - 24 * 60 * 60 * 1000) } } },
{ $group: { _id: "$questionId", total: { $sum: "$count" }}},
{ $sort: { total: -1 } },
{ $limit: 3 }
]);
return Questions.find({_id: {$in: claps.map((clap) => { return clap._id })}}, {fields: Questions.publicFields});
});
FindFromPublication.publish('questions.myactive', function() {
var claps = Claps.aggregate([
{ $match: { userId: Meteor.userId() } },
{ $group: { _id: "$questionId", latest: { $max: "$createdAt" }}},
{ $sort: { latest: -1 } },
{ $limit: 3 }
]);
return Questions.find({_id: {$in: claps.map((clap) => { return clap._id })}}, {fields: Questions.publicFields});
});
FYI, I wil investigate it later...
I have a non-trivial application at the moment, so it's going to be a bit difficult to extract the part of code that is causing the issue.
However, I am using "alanning:roles" and I found that when data on the current user gets updated the subscription will only have the current user. However, it's not consistent as of yet. I am in the midst of putting in console.log statements in your code to see what may be causing the problem.
The problem started manifesting in Meteor 1.3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.