我正在使用燒瓶應用程式從 mongodb 查詢資料。來自 mongodb 的檔案格式如下。
[{'organization_name': 'Example 1', 'date': '2021-10-15', 'url': 'https://www.example1.com/events/performances/641/2019-10-13/'}, {'organization_name': 'Example 2', 'date': '2021-10-21', 'url': 'https://file2.org/masterworks'}, {'organization_name': 'Example 3', 'date': '2021-10-21', 'url': 'https://file2.org/masterworks2'}]
現在基于 url 的查詢和搜索是這樣執行的
filter_stuff = {'url': 1, 'organization_name': 1, 'date':1, '_id': 0}
data = eventcol.find({'url': url}, filter_stuff)
此處搜索僅適用于確切的完整 url。如果給出了 url 的任何部分,那么如何進行搜索,所有具有該部分的資料都作為結果回傳。
如果搜索是,file2 那么結果是檔案,https://file2.org/masterworks and https://file2.org/masterworks2如果搜索是,events那么結果是https://www.example1.com/events/performances/641/2019-10-13/
uj5u.com熱心網友回復:
你能做這樣的事情嗎?
from pymongo import MongoClient
client = MongoClient()
db = client.test
def main(search_string):
collection = db.eventcol
for doc in collection.find({"url": {"$regex": search_string}}):
print(doc)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/462446.html
上一篇:MongoDB匯總每日贏/輸游戲,$cond始終為false
下一篇:比較嵌套陣列中的兩個欄位
