`

7: Pre-populate anything you can

阅读更多

原文截取如下:

 

If you know that your document is going to need certain fields in the future, it is more

efficient to populate them when you first insert it than to create the fields as you go.

 

Now, when you increment or set these counters, MongoDB does not need to find space

for them. It merely updates the values you’ve already entered, which is much faster.

 

For example, at the beginning of the hour, your program might do something like:

> db. pages. update({"_id" : pageId, "start" : thisHour}, 

. . . {"$inc" : {"visits.0.0" : 3}})

 

This idea can be extended to other types of data and even collections and databases

themselves. If you use a new collection each day, you might as well create them in

advance.

 

 

类似一个占位符之类的东西,好比op操作,更新比find space快。

 

猜想下:更新是替换掉那连续的内存空间内容还是说只换下指针而已

           增加新的field需要找新的sapce以及建立一定的指针关联

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics