Node.js 从mongodb/nodejs查询嵌套对象数组

Node.js 从mongodb/nodejs查询嵌套对象数组,node.js,json,mongodb,nested,Node.js,Json,Mongodb,Nested,我试图找出如何查询组件对象中的嵌套对象。数据是从已解析的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

我试图找出如何查询
组件
对象中的嵌套对象。数据是从已解析的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'
和其他类似的方法,但仍然无法得到过滤后的响应

任何洞察都会有所帮助,因为我一步一步地蹒跚前行

这是另一个查询,它会给我结果,但我想我的问题是将结果解析为变量

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;
使用点表示法(例如texto.Name)从嵌套对象中查询和检索字段,例如:

var query = {'texto.Name': 'Test WF'}
简单地

Regex用于不区分大小写

db.getCollection('TestQueries').find({"texto.Name":{
                                 '$regex' : '^test wa$', '$options' : 'i'
                                 }})
使用排序规则

db.fruit.createIndex( {"texto.Name": 1},{ collation: {
                     locale: 'en', strength: 2 
                     } } )

db.getCollection('TestQueries').find( 
            { "texto.Name": "test wa" } ).collation( { locale: 'en', strength: 2 } 
            )

很好的
Desc
!你所说的“以某种方式过滤”是什么意思?你能说得更具体一点吗?你到底想返回什么?我真的想进入组件级别并访问其子节点中的数据。我希望能够提取文件中每个节点的字段名和值。感谢您的输入,这是我的,但我得到的是db.getCollection不是一个函数var query={'texto.name':'Test WF'}cursor=db.getCollection('workflows')。find({query})(函数(err,result){if(err)throw err;console.log(result);db.close();});我只是在机器人3T上运行这个。这就是我习惯于收集的原因。我想你可以尝试使用db.collection db.collection()我有一个相同的数据流,但它给出的是所有数据,而不是匹配的数据。下面是我的代码。{“$match”:{“$or”:[{“产品”类别.产品列表.名称:{“$regex”:“*samo.*”,“$options”:“i”}]}
db.getCollection('TestQueries').find({"texto.Name":{
                                 '$regex' : '^test wa$', '$options' : 'i'
                                 }})
db.fruit.createIndex( {"texto.Name": 1},{ collation: {
                     locale: 'en', strength: 2 
                     } } )

db.getCollection('TestQueries').find( 
            { "texto.Name": "test wa" } ).collation( { locale: 'en', strength: 2 } 
            )