索引在子文档数组中的字段 [英] Indexing on a field which is in array of subdocuments

查看:89
本文介绍了索引在子文档数组中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出我从SQL Server移植到MongoDB的邮件系统的最佳设计 - 目前(在SQL Server中)存在存储邮件的树表:邮件,收件箱和已发送。消息存储在消息表中,收件箱/已发送包含每条消息的所有收件人/发件人的条目。

I'm trying to figure out the best design for the messaging system I'm porting from SQL Server to MongoDB - currently (in SQL Server) there are tree tables that store the message: Messages, Inbox and Sent. The message is stored in Messages table, and Inbox/Sent have entries for all recipients/senders for each message.

现在,在MongoDB中我想将这三者合并为一个集合,包含以下文件:

Now, in MongoDB I wanted to combine those three into one collection, with documents like this:

{
    _id: 
    subject:
    body:
    sender: {memid:, name:}
    recip: [{memid:, name:}, {memid:, name:}, {memid:, name:}, etc]

}

现在,我需要能够通过以下方式检索给定收件人的所有邮件memid,我必须快速完成,所以需要一个索引(我将有数亿个这样的条目)。所以,我的问题是 - 我可以通过数组中的文档字段进行索引吗?

Now, I need to be able to retrieve all messages for a given recipient by memid and I have to do it fast, so an index is required (I will have hundreds of millions of such entries). So, my question is - can I index by a field of a document in an array?

推荐答案

见这里 http://www.mongodb.org/display/DOCS/Multikeys

mongodb支持数组中文档字段的索引。

Index by a field of a document in an array is supported by mongodb.

这篇关于索引在子文档数组中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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