Skip to content
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

egg-mongoose动态连接其它mongo数据库 #5360

Open
daoshenjay opened this issue Sep 25, 2024 · 1 comment
Open

egg-mongoose动态连接其它mongo数据库 #5360

daoshenjay opened this issue Sep 25, 2024 · 1 comment

Comments

@daoshenjay
Copy link

请详细告知你的新点子(Nice Ideas):

我在配置文件中配置了默认使用的mongo数据库A,但是同时,因业务需要,我想在业务逻辑中动态去连接其他mongo数据库B,请问现在可以实现这个需求吗?
数据库A和数据库B中存在同名的表格,比如都有User表,在获取数据时是否会有冲突?

我做过的尝试:
我在代码中做了如下尝试,可以连接数据库B成功,但是不知道怎么获取数据
const db = mongoose.createConnection(urlB, options)
db.on('connected', async () => {
db.model.User.fineOne() // 这种方式不行
})

@svenjia
Copy link

svenjia commented Sep 30, 2024

不是可以配置多个clients么?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants