开发者

MongoDB For Trending Data

I have an app in which customers can partially define their schema by adding custom field to various domain objects we have. We are looking at doing trending data for these custom fields. I've been thinking about storing the data in a format which has the the changes listed on the object.

{
  _id: "id",
  custom1开发者_Python百科: 2,
  changes: {
             '2011-3-25': { custom1: 1 }
           }
}

This would obviously have to be less than the max document size (16mb) which I think is well within the amount of changes we'd have.

Another alternative would be have multiple records for every object change:

{
  _id: "id",
  custom1: 1,
  changeTime: '2011-3-25' 
}

This doesn't have the document restriction, but there would be more records, requiring more work to get the full change set for a record.

Which would you choose?


I think I'd be looking to go down the single document route if it will remain within the 16MB limit. That way, it's just a single read to load a record and all of it's changes which should be pretty darn quick. Having the changes listed within the document feels like a natural way to model the data.

In situations like this, especially if it's not something I've done before, I'd try to knock up a benchmark to test the approaches - that way, the pros/cons/performance of each approach presents itself to you and (hopefully) gives you confidence in the approach you choose.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜