1.5.30. fejezet, PyMongo
Beküldte pzoli - 2025, június 13 - 4:24du
Kapcsolódó hivatkozások
import os import time from dotenv import load_dotenv from pymongo import MongoClient load_dotenv() uri = os.getenv('MONGODB_URI') client = MongoClient(uri) try: db = client.get_database("population") cities = db.get_collection("cities") query = {"name": "Seoul"} ob = cities.find_one(query) print(ob) pipeline = [{'$match': {'operationType': 'insert'}}] resume_token = None with cities.watch(pipeline) as stream: while stream.alive: change = stream.try_next() if change is not None: print("Inserted document: %r" % (change.get('fullDocument'),)) continue time.sleep(10) except Exception as e: print("Unable to find the document due to the following error: ", str(e))
- A hozzászóláshoz be kell jelentkezni