我可以为多个Meteor应用程序使用相同的数据库吗?

Lor*_*ren 7 meteor meteor-accounts telescope

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

这应该可行吗?任何表现问题?

Aks*_*hat 6

这个问题是你必须共享集合名称.

如果你使用你的数据库,你也会突然使用你的其他应用程序在未来版本上使用的集合名称来保护Telescope.

你可以做的只是users如果你想要的话,分享收藏品.

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

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

Meteor.users = new Mongo.Collection("users", {
    _preventAutopublish: true,
    connection: Accounts.connection
});
Run Code Online (Sandbox Code Playgroud)

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

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

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