I have these codes now:
OneCollection.find({}, {fields: {'oneFiled.child1': 1}});
OneCollection.find({}, {fields: {'oneFiled.child2': 1}});
But I want to give a dynamically child filed name.
let childfield = "child1";
OneCollection.find({}, {fields: {'oneFiled.childfield': 1}}); // How to write this one?
How can I dynamically give the filed name? Thanks
Like this ?
let childField = 'child1';
let listFields = {};
listFields['oneField.'+childField]=1;
OneCollection.find({}, {fields: listFields });