MongoDB

来源:互联网 发布:轻薄笔记本 知乎 编辑:程序博客网 时间:2024/04/18 21:13

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存储。

原创粉丝点击