-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.3
-
Component/s: asyncio
-
None
I have some trouble.
When I use pymongo everything works all right:
{{import pymongo from pymongo import TEXT class Search(): # search in mongodbdef _init_(self, search): # connect to mongoDB self.search = search
self.myclient = pymongo.MongoClient("mongodb+srv://:@cluster0.ye4cx.mongodb.net/DATABASE?retryWrites=true&w=majority&ssl=true&ssl_cert_reqs=CERT_NONE")
self.mydb = self.myclient["info"]
self.mycol = self.mydb["comics"] def searchdb(self): # finds all comics by request self.mycol.create_index([('title', TEXT)], default_language='english')
self.find = self.mycol.find({"$text": {"$search": self.search}})
print(self.find) if self.find.count() == 0: return 0else: return (self.find)}}
But in motor AttributeError: 'AsyncIOMotorCursor' object has no attribute 'document_count'
{{import motor.motor_asyncio class Search(): # search in mongodbdef _init_(self, search): # connect to mongoDB self.search = search
self.myclient = motor.motor_asyncio.AsyncIOMotorClient("mongodb+srv://:@cluster0.ye4cx.mongodb.net/DATABASE?retryWrites=true&w=majority&ssl=true&ssl_cert_reqs=CERT_NONE")
self.mydb = self.myclient["info"]
self.mycol = self.mydb["comics"] async def searchdb(self): # finds all comics by request self.mycol.create_index([('title', 'text')], default_language='english')
self.find = self.mycol.find({"$text": {"$search": self.search}}) if self.find.document_count() == 0: return 0else: return self.find}}
- related to
-
MOTOR-628 If I try find() something, how can I find out if something was found or not?
- Closed