Is there a way to utilize a variable as a field name in a Mongo query within a Meteor application?
For instance...
This code snippet performs a find operation on my request controllers collection after capitalizing the collection name for the parent id of a child. The child field is named users.
window[Meteor.request.controller.capitalise()]["find"]({ _id: Session.get('parent_id'), users: params.child }).count()
While my controller is a variable name for the collection item, enabling a single line of code to find children of controller/collections, I need the ability to assign the child field name to a variable as well. In the example above, it's users but I aim for it to be a variable name.
I attempted this approach, but to no avail.
window[Meteor.request.controller.capitalise()]["find"]({ _id: Session.get('parent_id'), [Session.get('child_collection_name').decapitalise()]: params.child }).count()
where
Session.get('child_collection_name').decapitalise()
yields users
Any suggestions? Finding a way to incorporate a variable name in a Mongo query in Meteor would greatly streamline my code.