In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This series of articles are translated from "50 Tips and Tricks for MongoDB Developers". I can't find the Chinese version for the time being. Anyway, I have been studying mongodb deeply recently, so I just want to translate it. On the one hand, enhance the effect of our own learning, on the other hand, let the big family to experience what we mongodb users need to pay attention to.
First of all, I declare that my English level is not too high, and some English translation into Chinese can not find suitable words to express, so the original English words may appear in the article, or the translation in some places will be a little blunt, that is to say, there will be literal translation. The main purpose of translating this book is for everyone to learn and explore. If there is any inaccuracy in translation, or if there is a more accurate translation, please point out that I will correct it in time. Thank you in advance.
Tip#7.Pre-populate anything you can
Pre-fill what you can fill
If you know that in the future, you will definitely need some fields in your document, and it will be more efficient to populate them when you insert the document instead of creating them when you need them. For example, you are creating a site analytics application that can see how many users visit each page during the day. You will have a pages collection, and each document records the number of visits per minute and hour over the past 6 hours.
{"_ id": pageId, "start": time, "visits": {"minutes": [[num0,num1,...,num59], [num0,num1,...,num59]], "hours": [num0,num1,...,num5]}}
One advantage of doing this is that we know what the document will look like between now and some point in time. It is a number of visits per minute and hour from now on for the next 6 hours. There will be a new document in the next six hours.
Therefore, we need a batch task to insert these template documents in free time, or at a fixed time of day. The inserted template should look like the following.
{"_ id": pageId, "start": someTime, "visits": {"minutes": [[0meme 0min.meme 0], [0meme 0meme. Hours 0], [0meme 0min.meme 0], [0meme 0meme.
Now, when you increase these counters, mongodb does not need to allocate space for them now. Just update the value of the document that has been inserted, which will be faster.
For example, in the first hour, that's all you need to do.
Db.page.update ({"_ id": pageId, "start": thisHour}, {"$inc": {"visits.0.0": 3}})
This approach can also be extended to other types of data in collections and databases, and if you need a new collection every day, it's best to create them in advance.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.