如何在 Meteor 中动态赋予集合字段名称?

How to dynamically give the collection filed name in Meteor?

我现在有这些代码:

OneCollection.find({}, {fields: {'oneFiled.child1': 1}});
OneCollection.find({}, {fields: {'oneFiled.child2': 1}});

但是我想给一个动态的子文件名。

let childfield = "child1";
OneCollection.find({}, {fields: {'oneFiled.childfield': 1}});  // How to write this one?

如何动态给出文件名?谢谢

使用bracket notation构造字段对象如下:

var childfield = "child1",
    options = { fields: {} };

options["field"]["oneField."+childfield] = 1;
OneCollection.find({}, options); 

像这样?

let childField = 'child1';
let listFields = {};
listFields['oneField.'+childField]=1;
OneCollection.find({}, {fields: listFields });