New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support .$id
and other fields of DBRef
objects.
#759
Comments
Link
directive fails with mongomock harnessLink
directive fails with mongomock harness
Isn't this an issue with |
Hey @denivyruck, thanks for the response. I'll pop over and see what the |
import asyncio
from mongomock_motor import AsyncMongoMockClient
from motor.motor_asyncio import AsyncIOMotorClient
from bson import DBRef
async def test__aggregate_lookup_dbref():
client = MockOrActualClient('mongodb://localhost:27017')
await client.db.a.insert_one({
'_id': 1,
'refs': [DBRef('b', 2), DBRef('b', 4, 'db')],
})
await client.db.b.insert_many([
{'_id': 2, 'should': 'include'},
{'_id': 3, 'should': 'skip'},
{'_id': 4, 'should': 'include'}
])
actual = list(await client.db.a.aggregate([
{'$lookup': {
'from': 'b',
'localField': 'refs.$id',
'foreignField': '_id',
'as': 'b'
}}
]).to_list(None))
assert [{
'_id': 1,
'refs': [DBRef('b', 2), DBRef('b', 4, 'db')],
'b': [
{'_id': 2, 'should': 'include'},
{'_id': 4, 'should': 'include'}
]
}] == actual, actual This test case works with mongo 5, 4 (and fails on 3 because of field name '$id'), but fails with As far as I can tell, elif DBRef and isinstance(result, DBRef):
if key_item == '$id':
result = result.id
elif key_item == '$db':
result = result.database
elif key_item == '$ref':
result = result.collection
else:
raise KeyError(key_index) and |
Hi, I'm not familiar with |
Link
directive fails with mongomock harness.$id
and other fields of DBRef
objects.
Hi MongoMock team.
I've been using your brilliant library for a while and have recently encountered an issue when producing test cases for Beanie with Linked documents.
When attempting to create a linked document I get the following error;
I have resolved the problem with the following change to
beanie/odm/documents.py
;More explicitly, adding the collection name in a
name
attribute ofcollection_meta.motor_collection
.I'm logging the issue with you folks as the error doesn't manifest itself when interacting with an actual mongodb so presumably it isn’t an issue Beanie or the Async engine.
If I'm in the wrong place, please let me know. If you want me to have a dig into the code and PR-it then happy to take a look too - I ask as it might be as long reviewing my PR as making the change and merging it yourselves.
The text was updated successfully, but these errors were encountered: