【发布时间】:2019-02-28 22:24:27
【问题描述】:
我试图弄清楚如何查询Components 对象内的嵌套对象。数据是从解析的 json 文件中插入的。
查询
var query = {}
cursor = db.collection("workflows").find(query).toArray(function(err, result) {
if (err) throw err;
console.log(result);
db.close();
});
当我运行上面的查询时会返回此数据:
此时我只是试图让它以某种方式过滤。我尝试了
Name:'Test WF'和其他变体,但仍然无法获得过滤响应。
[ { _id: 5c77040838f9d322b89bbd82,
texto:
{ _id: 12,
LocalCachePath: 'Z:\\Test\\Cache',
SharedCachePath: [],
Name: 'Test WF',
Desc: 'I\'m testing',
Components: [Array] } },
{ _id: 5c7704164413692978a9dd1a,
texto:
{ _id: 'Workflow-2019.02.22-23.21.15-MKRU',
LocalCachePath: 'Z:\\MAITest\\Cache',
SharedCachePath: [],
Name: 'Test WF',
Desc: 'I\'m testing',
Components: [Array] } },
{ _id: 5c77046335b012379c99951b,
texto:
{ _id: '154',
LocalCachePath: 'Z:\\Test\\Cache',
SharedCachePath: [],
Name: 'Test WF',
Desc: 'I\'m testing',
Components: [Array] } },
{ _id: 5c7704787bde6f36543d1016,
texto:
{ _id: 'Workflow-2019.02.22-23.21.15-MKRU',
LocalCachePath: 'Z:\\Test\\Cache',
SharedCachePath: [],
Name: 'Test WF',
Desc: 'I\'m testing',
Components: [Array] } } ]
任何见解都会对我一次步履蹒跚的这一步有所帮助。
这是另一个给我结果的查询,但我想我的问题是将我的结果解析为变量。
var query = {'texto.Components.0.Name' : {$gt: ''}}
// var query = {'testo.Name' : {$gt: ''} }
cursor = db.collection("workflows").find(query).toArray(function(err, result) {
if (err) throw err;
【问题讨论】:
-
好
Desc! “以某种方式过滤”是什么意思?你能说得更具体点吗? -
您到底想要返回什么?
-
我真的很想进入组件级别并访问其子节点中的数据。我希望能够为文件中的每个节点提取字段名称和值。
标签: node.js json mongodb nested