In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Python, python3.
First get all the data from the database db ['test']. Find ({}, {_ id:0}), and then for the results
Demos = db ['demo'] .find ({}, {"_ id": 0}) for cursor in demos: do_something ()
However, when the do_something function takes too long and does not operate on the cursor for a long time, cursor times out on the mongodb server.
Solution
1. Set no_cursor_timeout = True. Never time out. The cursor connection will not be closed actively and needs to be closed manually.
Demos = db ['demo'] .find ({}, {"_ id": 0}, no_cursor_timeout = True) for cursor in demos: do_something () demo.close () # close the cursor
2. Set the number of documents returned by batch_size. By default, it should be 20 documents (I can't remember 233333). You can set it smaller.
# return only one document at a time
Demos = db ['demo']. Find ({}, {"_ id": 0}) .batch_size (1) for cursor in demos: do_something ()
Note: this method may still occur for more than 10 minutes and still does not return, such as you do some very time-consuming operations in do_something, depending on the actual situation.
Additional knowledge points:
Mongodb conditional operators, "$lt", "$lte", "$gt", "$gte", "$ne" are all comparison operators
Corresponds to "=", "! =".
Atomic operators: "$and", "$or", "$nor".
[2]:
Db.runCommand (
{
Distinct: "sofang_xinfang", key: "city"
}
)-distinct finds out how many city fields there are?
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.