Questions tagged [motor-asyncio]

14 questions
4
votes
1 answer

RuntimeError: Event loop is closed - motor, asyncio

I am not able to run this test, i always have the same error RuntimeError: Event loop is closed What i need to add to this code? from motor.motor_asyncio import AsyncIOMotorClient import pytest import asyncio client =…
Cristoff
  • 149
  • 6
3
votes
2 answers

Asyncio (Quart) throwing Task attached to a different loop error when connecting to MongoDB with motor

I have created a webapp with Quart using MongoDB and using Motor.Asyncio. When the app attempts to query the DB an error is thrown: Task
blindChicken
  • 352
  • 4
  • 13
1
vote
1 answer

MongoDB query does not update document record

Im using pymongo version 4.3.3 and motor version 3.1.2 This is my code: async def add_reputation_to_db( self, guild_id: hikari.Snowflake, user_recieve_id: hikari.Snowflake, ) -> None: await self._guild_collection.update_one({'_id':…
minikslyh
  • 11
  • 2
1
vote
0 answers

'NoneType' object has no attribute 'get_collection', FastAPI + Mongodb

I am doing a test with FastAPI about the register of one user in the app. While app is running i can register a user perfectly but when i try to make a test with pytest about the same method i have problems, it doesn't recognise the…
Cristoff
  • 149
  • 6
1
vote
1 answer

asyncio.run fails when loop.run_until_complete works

This code fails: import asyncio from motor import motor_asyncio _client = motor_asyncio.AsyncIOMotorClient() _db = _client.db users = _db.users async def main(): await users.create_index( 'login', unique=True ) if…
sanyassh
  • 8,100
  • 13
  • 36
  • 70
0
votes
0 answers

MongoDB - Beanie ODM write, update, delete operations - tradeoffs in linked vs embedded documents

In a python project i am using Beanie ODM to interact with a Mongo database. Beanie ODM supports Relations, see: https://beanie-odm.dev/tutorial/relations/ I have a cascaded document structure like this: Countries -> States -> Cities …
0
votes
0 answers

How to delete many documents with Beanie ODM linked documents

I am following the example of the Beanie ODM docs on how to delete a single document: https://beanie-odm.dev/tutorial/relations/#delete passing link_rule=DeleteRules.DELETE_LINKS to the delete method. For a single document that works, but when i try…
0
votes
0 answers

Memory leak while querying a mongodb collection using motor

I am facing a memory leak issue and I am not understanding where exactly can be the problem. I am simply doing a collection.find(query) multiple times in a for loop. I am using python 3.6.5 and motor 2.5.1 to query a collection. The following code…
0
votes
0 answers

Scrapy ItemPipeline - "RuntimeError: await wasn't used with future"

Trying to drop duplicates by counting documents with same url. Using Motor (an async driver for MongoDB) for that purposes. Here a process_item function: according to the docs async def process_item(self, item, spider): response =…
0
votes
0 answers

Multi query in MongoDB to single collection to get complex sort?

Through what to make requests of this kind in MongoDB (python, motor)? There is a Collection of Documents. It is necessary to display them in one list in the following order: Urgent first. Further unfulfilled. Further leftovers sorted by date from…
Se Gu
  • 33
  • 5
0
votes
1 answer

Python - getting document from MongoDB [motor_asyncio]

on MongoDB , create "security" collection with a uniq index on "username" , I'm using motor.motor_asynci for working with Mongo. trying to fetch document related to "username" as following: from motor.motor_asyncio import AsyncIOMotorClient def…
AviC
  • 354
  • 1
  • 5
  • 15
0
votes
1 answer

Cannot find_one record in MongoDB with custom _id's

I have a MongoDB database where I overwrote the _id field manually using some generated tags (duplicates are not an issue). Trouble is, I am trying to find_one searching by _id but it continuously returns None and I cannot figure it out for the life…
0
votes
0 answers

Python Montor asyncio with srv remote connection is being refused by mondodb

I've been working with pymongo module to connect to mongodb for a while and I haven't had any problems with it, but now, I have to process some heavy info (about 1 million docs daily or so) and I wanted to try the async module Motor to work with.…
-1
votes
1 answer

Testing AsyncIO MongoDB function (Asyncio Motor Driver)

I am pretty new to AsyncIO, and looking for a bit of help. I have a basic class that runs an aggregation pipeline, which works perfectly in production: class BasePipeline2: client: motor.AsyncIOMotorClient db: motor.AsyncIOMotorDatabase …
garyj
  • 1,302
  • 2
  • 13
  • 22