I want use a variable in Key inside a find() in mongodb. I want to do a request similar to select value from table;.
I tried this: value = '{ "' + axey.options[i].value + '" : 1, "_id" : 0 }';
and I do my request in this way : Validation.find({}, value ).fetch();
Someone know how can I use my value like a "Key" and not like a value ?
Use the bracket notation to construct the projection document. You also need to include the field specifier in your projection document. For example:
var projection = { "fields": { "_id": 0 } };
projection["fields"][axey.options[0].value] = 1;
Validation.find({}, projection ).fetch();
I didn't understand your question clearly though if you want to know if certain key in your documents exists as you mentioned select key in table than you can do by this.
Collection.find("keyName": {$exists:true}).fetch();