mongoengine connection and multiple databases

前端 未结 1 731
你的背包
你的背包 2021-01-13 16:29

I have 2 databases I want to query from, but I only get results from one. I\'m using mongoengine with python and graphene (it\'s my first time). I\'ve exhausted my search an

1条回答
  •  旧巷少年郎
    2021-01-13 16:53

    If each of your model is bound to a different database. You should use something like this (cfr docs):

    connect('workouts', alias='dbworkouts')  # init a connection to database named "workouts" and register it under alias "dbworkouts"
    connect('users', alias='dbusers')    
    
    class Workout(Document):
        meta = {"db_alias": "dbworkouts"}
        workoutID = UUIDField()
        ...
    
    class UserModel(Document):
        meta = {"db_alias": "dbusers"}
        userID = UUIDField()
        ...
    

    0 讨论(0)
提交回复
热议问题