开发者

large set implementation in MongoDB

I have a data set in MongoDB that involves a large set of emails and I need to be able to add emails to the set and being 开发者_开发知识库able to check if certain emails are in the set. I thought of doing with document structure like this:

{'key': 'foo', 'emails':['mail@one.com','mail@two.com', ...]}

and use $addToSet and $in. But the problem is that Mongo has 4MB document limit and if there's a lot of emails it could be not enough. I could split it info key/email parts but I'm worried it would make both matching (since emails aren't in one place now) and inserting (since I'd need to check for uniqueness) slower. So, what would be the best way to do this?


Depending on how many sets of emails you're going to have you could make each set of emails a collection where each document consisted of only the email address. You could then create a unique index on the email address:

db.foo.ensureIndex({email:1},{unique:true})

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜