3

我想通过嵌套数组中存在字符串来检索文档。例如,数据(表示句子的依赖解析)如下所示:

{'tuples': [['xcomp', 'multiply', 'using'], 
            ['det', 'method', 'the'], 
            ['nn', 'method', 'foil'], 
            ['dobj', 'using', 'method']]}

我找到的最接近的解决方案假定这['nn', ...]tuples列表的第二个位置:

 db.c.find({'tuples.2.0' : 'nn'})

有没有办法放松固定位置?元组(不是它们的内容)可以按任何顺序排列。

其次,能够检索具有 的文档真的很棒 ['nn', 'method', X],这意味着它们的依赖解析中的名词“方法”。

谢谢!

4

1 回答 1

4

知道了!

db.c.find({'tuples' : {$elemMatch : {$all : ['nn']}}})
db.c.find({'tuples' : {$elemMatch : {$all : ['nn','method']}}})
于 2011-03-09T19:08:01.587 回答