简体   繁体   English

按集合的MongoDB分片

[英]MongoDB sharding by collection

I have an application which creates a collection in MongoDB for every user where a collection is expected to have at most 100,000 documents (a few "big" users are like this while many "small" users only have less than 10,000 documents). 我有一个应用程序,该应用程序在MongoDB中为每个用户创建一个集合,该集合预计最多具有100,000个文档(几个“大”用户是这样的,而许多“小”用户只有少于10,000个文档)。 Now the number of users grows and I want to shard my database. 现在用户数量增加了,我想分片数据库。 Is it possible to say "put this collection (thus this user) on this shard and that collection on that shard, but do not shard documents inside a collection further", and is it possible to do this automatically? 是否可以说“将此集合(由此用户)放在此分片上,然后将该集合放在该分片上,但不将其进一步分片到集合中”,并且可以自动执行此操作吗?

Edit: I'm already aware of MongoDB's standard sharding design now, but my application was scaled up from a small application for single person's use, where a nedb datastore is created for the user. 编辑:我现在已经知道MongoDB的标准分片设计,但是我的应用程序是从一个小型应用程序扩展到供单个人使用的,其中为用户创建了nedb数据存储。 When the multi-user support was added, it was an obvious choice to create a nedb datastore for every user so many parts of my application could stay unchanged. 添加多用户支持后,为每个用户创建nedb数据存储是一个显而易见的选择,因此我的应用程序的许多部分都可以保持不变。 When I migrated it to MongoDB, since one nedb datastore is the equivalent of a MongoDB collection, I was using one collection per user. 当我将其迁移到MongoDB时,由于一个nedb数据存储相当于一个MongoDB集合,因此我为每个用户使用一个集合。 Given the current situation, I wonder the quickest way (~= with the smallest change to my application and overall configurations) to solve the current performance issue. 考虑到当前的情况,我想知道最快的方法(〜=对我的应用程序和整体配置的更改最少)来解决当前的性能问题。

Sharding is done on a collection and how the sharded collection is broken up is based on the shard key (where one or more object elements from your collection make up the key). 分片是在集合上完成的,分片集合的分解方式是基于分片 (由集合中的一个或多个对象元素组成的键)。

It might be better to rethink your document design. 重新考虑您的文档设计可能会更好。 You could have all users in one collection and then use the user id as the shard key . 您可以将所有用户都放在一个集合中,然后将用户ID用作分片键 That would shard each user as a whole and do it automatically. 这将使每个用户整体分片并自动执行。

See Mongodb's Sharding documentation for more information on sharding. 有关分片的更多信息,请参见Mongodb的分片文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM