查询MongoDb中的嵌套数组

编程入门 行业动态 更新时间:2024-10-18 18:16:04
本文介绍了查询MongoDb中的嵌套数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想通过嵌套数组中字符串的存在来检索文档.例如,数据(表示句子的依存关系分析)看起来像:

I would like to retrieve documents by the presence of an string in a nested array. For example, the data (representing a dependency parse of a sentence) looks like:

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

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

The closest solution I've found assumes that ['nn', ...] is the second position of the tuples list-of-lists:

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

是否有一种方法可以放松固定位置?元组(不是它们的内容)可以是任意顺序.

Is there a way to relax the fixed position? The tuples (not their contents) can be in any order.

第二,能够检索具有['nn', 'method', X]的文档确实很棒,这意味着在其依赖项解析中有一个名词方法".

Secondly, it would be really great to be able to retrieve documents that have ['nn', 'method', X], meaning a noun "method" in their dependency parse.

谢谢!

推荐答案

知道了!

db.c.find({'tuples' : {$elemMatch : {$all : ['nn']}}}) db.c.find({'tuples' : {$elemMatch : {$all : ['nn','method']}}})

更多推荐

查询MongoDb中的嵌套数组

本文发布于:2023-10-23 05:38:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519952.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   数组   MongoDb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!