MongoDB

1. MongoDB

    In MongoDB there are no server-side joins.

    Generally, you will want one database collection for each of your top level objects.

    You do not want a collection for every “class” – instead, embed objects.

    Data within a Mongo collection tends to be contiguous on disk. Thus, table scans of the collection are possible, and efficient. Collections are very important for high throughput batch processing.

    Each record is a document. A document, however, more closely represents an object as a whole.

   

2. Design a MongoDB model

    When using mongodb, a general rule of thumb is that you use embeding and copying of data when it seems reasonable and fallback to referencing seperate entities when the user case demands it.

    So one of the main decision to take when designing a MongoDB model, is what should be a top level document and what should be embedded in another document?

There is no server-side relations between documents, so each reference requires an additional trip from the client.

3. Lift: Mong-Record

    Generally speaking each Lift Mong-Record entity you create represents a collection. By default, the collection will be a pluralized name of the class. Which means if you have a class “User”extend mongrecord[User] you will get a collection named users in MongoDB. You can specifiy the collection name in companion object by override collectionName method as below:

override def collectionName = “mypersons”

如何选择是否使用embed document?

对于写频繁的,最好单独存入collecton中,然后关联。

对于一次写入,基本不更新的,则使用embed document存储。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值