将多个Nodejs客户端连接到Mongodb

时间:2022-10-10 03:06:01

I am running an app on Heroku and I want to send a notification every morning at 8. I have about 200k users and it takes a long time and slows down my app, so I would like to separate the two and keep running my API on one instance, and have a separate instance just for sending the notification in the morning.

我正在Heroku上运行一个应用程序,我想每天早上8点发送一个通知。我有大约20万用户,这需要很长时间并且减慢了我的应用程序,所以我想将两者分开并继续运行我的API一个实例,并且有一个单独的实例,仅用于在早上发送通知。

How can I have two Nodejs servers using the same Mongodb database (and therefore the same models).

如何使用相同的Mongodb数据库(因此相同的模型)有两个Nodejs服务器。

I do not understand how to connect the two instances to the same database (I am using MLab on Heroku) without copying the model schema. Because in that case, if I modify it on one instance, I would need to do the same to the other, and it doesn't make sense to me.

我不明白如何将两个实例连接到同一个数据库(我在Heroku上使用MLab)而不复制模型模式。因为在这种情况下,如果我在一个实例上修改它,我需要对另一个实例做同样的操作,这对我来说没有意义。

I hope it is clear enough. Thank you

我希望它足够清楚。谢谢

1 个解决方案

#1


0  

TGrif: thanks a lot, I just used MongoDB native driver, and it works. I've always used Mongoose and didnt even think about looking for alternatives. Documentation here: https://github.com/mongodb/node-mongodb-native

TGrif:非常感谢,我只使用了MongoDB本机驱动程序,它可以工作。我一直使用Mongoose,甚至没有想过寻找替代品。文档:https://github.com/mongodb/node-mongodb-native

Thank you

谢谢

#1


0  

TGrif: thanks a lot, I just used MongoDB native driver, and it works. I've always used Mongoose and didnt even think about looking for alternatives. Documentation here: https://github.com/mongodb/node-mongodb-native

TGrif:非常感谢,我只使用了MongoDB本机驱动程序,它可以工作。我一直使用Mongoose,甚至没有想过寻找替代品。文档:https://github.com/mongodb/node-mongodb-native

Thank you

谢谢