On this data platform, an operation is to get related items through keywords. The previous method is accurate matching, Which is annoying, after all, not everyone can remember the complete keywords and project names, which is really disturbing. Dbshell mode is used for Fuzzy queries, db. project. find ({name: xiaorui. cc }). In pymongodb
On this data platform, an operation is to get related items through keywords. The previous method is accurate matching, Which is annoying, after all, not everyone can remember the complete keywords and project names, which is really disturbing. For Fuzzy queries in mongodb shell mode, db. project. find ({name:/xiaorui. cc /}). In pymongodb
On this data platform, an operation is to get related items through keywords. The previous method is accurate matching, Which is annoying, after all, not everyone can remember the complete keywords and project names, which is really disturbing.
For Fuzzy queries in mongodb shell mode, db. project. find ({'name':/xiaorui. cc /}). This cannot be the case in pymongodb. I thought it was similar to pymongo and always encountered errors. I finally read the document to solve the problem.
Db. project. find ({'name':/CAR/}) {"_ id": 139, "black_list": [], "created_on": ISODate ("2014-10-08T15: 09: 41.560Z ")," effective_time ": [1412697600,141 2697600]," industry_id ": 1000," name ":" card auto "," regex ": 0," status ": 0, "topic_ids": [2007,200 8, 2009,201 0, 2011,201 2, 2013,201 4, 2015,201 6, 2017,201 8, 2019,202 0, 2021,202 2, 2023,202 4, 2025,202 6, 2027,202 8, 2029,203 0, 2031,203 2], "user_id": 44, "white_list": []}
The following is a regular fuzzy query method using pymongo in python. One is the extension provided by mongo, regex, and the other can be operated by embedding the import re module.
Note:
Old rule: the original article address is blog. xiaorui. cc... Crawler, fuck!
In [76]: aOut [76]: '\ xe6 \ xb1 \ xbd \ xe8 \ xbd \ xa6' In [77]: print a car In [78]: list (db. project. find ({'name': {'$ regex': a}) Out [78]: [{U' _ id': 139, u'black _ list ': [], u'created _ on': datetime. datetime (2014, 10, 8, 15, 9, 41,560 000), u'valid _ time': [1412697600,141 2697600], u'industry _ id': 1000, u'name': U' \ u7231 \ u5361 \ u6c7d \ u8f66 ', u'regex': 0, u'status': 0, u'topic _ id ': [2007,200 8, 2009,201 0, 2011,201 2, 2013,201 4, 2015,201 6, 2017,201 8, 2019,202 0, 2021,202 2, 2023,202 4, 2025,202 6, 2027,202 8, 2029,203 0, 2031,203 2], u 'user _ id': 44, u 'White _ list': []}] In [79]: list (db. project. find ({'name': re. compile (a)}) Out [79]: [{U' _ id': 139, u'black _ list': [], u'created _ on ': datetime. datetime (2014, 10, 8, 15, 9, 41,560 000), u'valid _ time': [1412697600,141 2697600], u'industry _ id': 1000, u'name': U' \ u7231 \ u5361 \ u6c7d \ u8f66 ', u'regex': 0, u'status': 0, u'topic _ id ': [2007,200 8, 2009,201 0, 2011,201 2, 2013,201 4, 2015,201 6, 2017,201 8, 2019,202 0, 2021,202 2, 2023,202 4, 2025,202 6, 2027,202 8, 2029,203 0, 2031,203 2], u'user _ id': 44, u'white _ list': []}] In [80]:
Original article address: subtotal-python calls the pymongo Fuzzy Regular Expression query method. Thanks to the original author for sharing.