我可以为多个 Meteor 应用程序使用同一个数据库吗? [英] Can I use the same DB for multiple Meteor apps?

查看:44
本文介绍了我可以为多个 Meteor 应用程序使用同一个数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用例:我在 app.foo.com 上构建的应用程序,以及 community.foo.com 上的一个望远镜实例,在单独的应用程序服务器上.他们共享的唯一集合是 users.我会给两个应用程序提供相同的 mongo url 和 oplog url,并确保除了 users 之外,两个应用程序之间的集合名称没有重叠.

Use case: the app I built on app.foo.com, and an instance of telescope on community.foo.com, on separate application servers. The only collection they'd share is users. I would give the same mongo url and oplog url to both apps, and make sure that other than users, collection names did not overlap between the two apps.

这应该可以正常工作吗?任何性能问题?

Should this work fine? Any performance concerns?

推荐答案

这样做的问题是你必须共享集合名称.

The problem with this is you have to share the collection names.

如果您使用您的数据库,您也可以避免 Telescope 突然使用您的其他应用在未来版本中也使用的集合名称.

If you use your databases you're also insured against Telescope suddenly using a collection name that your other app uses on a future version too.

您可以分享users 集合(如果需要).

What you can do is only share the users collection if you want.

服务器端代码(客户端不需要)

Accounts.connection = DDP.connect("https://<telescope app url>");

Meteor.users = new Mongo.Collection("users", {
    _preventAutopublish: true,
    connection: Accounts.connection
});

或者更直接(如果您允许 OAuth 登录,则不推荐)

Or more directly (not preferable if you're allowing OAuth logins)

var database = new MongoInternals.RemoteCollectionDriver("<mongo url of telescope app>");
Meteor.users = new Mongo.Collection("users", { _driver: database });

所以这个应用现在使用 Telescope 应用的用户集合.

So this app now uses the Telescope app's user's collection.

这篇关于我可以为多个 Meteor 应用程序使用同一个数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆