Collection.find() on a computed value?


#1

I have searched for quite a while to find the answer to this, and nothing seems to be quite right. Also, I’m new to Meteor and MongoDb so forgive me if I’ve missed something.

My situation:

I have a Foo collection whose documents have three numeric values. I want to be able to return documents who sum of the three fields matches a query. For example, return a set of Foo documents where Field1 + Field2 + Field3 >= X.

I have no trouble doing a Foos.find({}) to return all Foo documents, and including a helper that allows me to return a computed Sum field fore each document. But how can I filter the collection based on this Sum field?

Foos.find({Sum: {$gte: 500}}) does not work. Is this possible?


#2

Sorting by dynamic field is tricky as i found out when i was using reactive table https://github.com/aslagle/reactive-table#virtual-columns

You could however try this https://github.com/englue/meteor-publish-composite and see if it can fit your need.