Feature-request: Allow to use both ObjectIDs and DBRefs as links (To ease migration from MongoEngine) #893
cdelacruzpinto
started this conversation in
Feature Request
Replies: 1 comment
-
|
I would have a use case for this as well. We are migrating from node to FastAPI-Beanie and the mongo database can't change from ids to DBrefs. We would like to use links to resolve documents with fetch/pre-fetch as opposed to manually fetching documents in a separate query. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Suppose we have the following structure:
`
class Door(Document):
height: int = 2
width: int = 1
class House(Document):
name: str
door: Optional[Link[Door]]
`
Currently, a link is only resolved automatically by Beanie if in Mongo if it's represented in the actual database like this:
door: DBRef('Door', '65e97bc6e6b5d4fa42bc2581')Currently, if I replace door: DBRef('Door', '65e97bc6e6b5d4fa42bc2581') with door: ObjectId("65e97bc6e6b5d4fa42bc2581" in the database, beanie also infers the collection name, because a "print(house1.dict())" yields this:
{'id': '65e97bd7a4da61784f74bfbf', 'name': 'Casa carlos', 'door': {'id': '65e97bd7a4da61784f74bfbf', 'collection': 'Door'}}, But won't resolve the actual content of the door object which is{'id': '65e97bd7a4da61784f74bfbf', 'name': 'Casa carlos', 'door': {'id': '65e97bd7a4da61784f74bfbe', 'height': 1, 'width': 2}}
In a nutshell, my feature request is:
Support links defined in both ways:
door: ObjectId("65e97bc6e6b5d4fa42bc2581")
and DBRef('Door', '65e97bc6e6b5d4fa42bc2581')
This makes migrating a service from MongoEngine to Beanie easier, as MongoEngine represents links in both ways.
Beta Was this translation helpful? Give feedback.
All reactions