Meteor angular collection search method not working
I am trying to optimize my angular / meteor code. I have a collection
Customers = new Mongo.Collection("Customers");
and the way I was showing them was:
ng-repeat="customer in customerController.customers | filter: {customerStore: myStore} ">
and in my CustomerController
this.customers = $meteor.collection(customers);
This approach (while it works) is now starting to take up a lot of memory on the client server as they add more and more storage.
So I tried to filter out the server side before sending the information to the client.
NEW CODE:
the collection code is the same
Customers = new Mongo.Collection("Customers");
Ng-repeat code is different
ng-repeat="customer in customerController.getCustomers(myStore) ">
and my controller now has this method:
this.getCustomers = function(findByStore){
return Customers.find({customerStore.$ : findByStore});
}
The problem is that it returns a new collection every time, so angular treats it as a different object and tries to re-render the page.
https://docs.angularjs.org/error/ $ rootScope / infdig? p0 = 10 and p1 =% 5B% 5B% 7B% 22msg% 22:% 22fn:% 20regularInterceptedExpression% 22% 22newVal% 22: 21,% 22oldVal% 22: 19% 7D% 5D,% 5B% 7B% 22msg% 22 :% 22fn:% 20regularInterceptedExpression% 22% 22newVal% 22: 23,% 22oldVal% 22: 21% 7D% 5D,% 5B% 7B% 22msg% 22:% 22fn:% 20regularInterceptedExpression% 22% 22newVal% 22: 25,% 22oldVal% 22: 23% 7D% 5D,% 5B% 7B% 22msg% 22:% 22fn:% 20regularInterceptedExpression% 22% 22newVal% 22: 27,% 22oldVal% 22: 25% 7D% 5D,% 5B% 7B% 22msg % 22:% 22fn:% 20regularInterceptedExpression% 22% 22newVal% 22: 29,% 22oldVal% 22: 27% 7D% 5D% 5D
One common mistake is binding to a function which generates a new array every time it is called.
Someone suggested that I try
return $meteor.collection(Customers.find({'customerStore.$' : findByStore}));
but then i get the error
TypeError: The first argument of $meteorCollection must be a function or a have a find function property.
source to share
No one has answered this question yet
Check out similar questions: