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

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

问题描述

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

我有这样的文档集合:

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



首先,我想要列表中列出所有标签的所有Url。
我通过quering解决了这个问题:

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

但是,这个查询返回整个正确的文档,insted只有正确的文档,只有我有标签我要找的结果是:

  {
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 VOTES:2}]
}

因为我只要求标签[ 问题,答案]。



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



谢谢!

解决方案

感谢Robert。我意识到,我正在寻找的功能目前尚未实现。以下是问题的链接。我希望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}
         ]
}

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.

The result I'm looking for is:

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

and not:

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

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

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.

Thanks!

解决方案

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天全站免登陆