MongoDB - 在结果集中过滤内部数组的内容 [英] MongoDB - Filtering the content of an internal Array in a resultset

查看:15
本文介绍了MongoDB - 在结果集中过滤内部数组的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 MongoDB 新手,不知道如何解决下一个问题:

I'm new using MongoDB, and I don't know how to solve the next problem:

我有一个这样的文档集合:

I have a collection of documents like this:

{
 "URL": "www.stackoverflow.com",
 "TAGS": [
         {"NAME": "question", "VOTES": 3},
         {"NAME": "answer", "VOTES": 5},
         {"NAME": "problem", "VOTES": 2}
         ]
}

首先,我想要所有具有列表中给出的所有标签的 URL.我已经通过查询解决了这个问题:

First of all, I wanted all the Urls that have all the tags given in a list. I have solved this by quering:

db.links.find( { "Tags.Name" : { $all: ["question","answers"] } } );

但是这个查询返回整个正确的文档,只包含正确的文档,只有我要求的标签.

But this query return the whole correct document, insted of only the correct document with only the tags I have asked for.

我正在寻找的结果是:

{
 "URL": "www.stackoverflow.com",
 "TAGS": [{"NAME": "question", "VOTES": 3},
         {"NAME": "answer", "VOTES": 5}]
}

而不是:

{
 "URL": "www.stackoverflow.com",
 "TAGS": [{"NAME": "question", "VOTES": 3},
         {"NAME": "answer", "VOTES": 5},
         {"NAME": "problem", "VOTES": 2}]
}

因为我只要求标签 ["question","answers"].

Because I've only asked for the tags ["question","answers"].

我想过使用MapReduce或者解析resultset,但不知道是不是解决问题的正确方法.也许有一个内置函数可以更有效地解决它.

I thought about using MapReduce or parsing the resultset, but I don't know if it is the correct way of solving the problem. Maybe there is a builtin function that solve it more efficiently.

谢谢!

推荐答案

感谢 Robert.我已经意识到我正在寻找的功能目前尚未实现.这是问题的链接.希望MongoDB社区能在短时间内实现.谢谢!

Thanks Robert. I have realized that the featured I'm looking for is not implemented at this moment. Here is the link of the issue. I hope that the MongoDB cominuty implements it in a short time. Thanks!

这篇关于MongoDB - 在结果集中过滤内部数组的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆