Pregunta

I need to design a mongodb database, which is used to store logs:

for example:

{ "_id" : 2, "date" : "Wed Feb 19 2014 22:02:01 GMT+0800 (CST)", "user" : 342 }

the query will be used like this:

db.test.find({"user":342, "date":{"$lt" : new Date(2013, 3, 2)})

So I must build an index such as

{user:1, date:1}

there are aboult 3 million logs per day.

So I think the collection will grow too big after several months, the index query will be slow, so I want to shard the logs into many collections, one collection only store one day's logs.

if I want to query several days' logs, I will query several collections and merge the result.

should I shard the database into many collections, one collection for one day?

Is there some advantages or disadvantages for such sharding?

¿Fue útil?

Solución

It is depend upon your application and the business logic you implemented. I do not know how your database is design but if you have not requiring the older data frequently it is better to keep the log in a separate database and get it. so it will not affect to your current database. still it need the understanding of you application how you require that.. and based upon that you can design your database...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top