无法使Account-Base包指向正确的数据库

时间:2015-04-14 08:36:52

标签: mongodb meteor

我有一个Meteor应用程序。使用不同于默认'流星的数据库。之一:

var database = new MongoInternals.RemoteCollectionDriver(" mongodb://127.0.0.1:3001 / my-db");

但是,每次我使用Accouts-Base软件包注册新用户时,它都会继续将新用户记录添加到“流星”中的“用户”集合中。数据库。有没有办法将此软件包与备用数据库一起使用?

P.S。如果这有任何不同,我在开发环境中。

1 个答案:

答案 0 :(得分:1)

查看directly at the code for the accounts-base package(Meteor v 1.0.4),看起来他们没有正式支持为用户集合设置数据库的方法。从代码中可以看出,服务器始终使用默认的Meteor.connection连接:

Meteor.users = new Mongo.Collection("users", { // line 141
  _preventAutopublish: true,
  connection: Meteor.isClient ? Accounts.connection : Meteor.connection
});

上面设置了Accounts.connection,但明确 支持

// ~ line 118
if (Meteor.isClient
....
if (typeof __meteor_runtime_config__ !== "undefined" &&
  __meteor_runtime_config__.ACCOUNTS_CONNECTION_URL) { 
    // Temporary, internal hook to allow the server to point the client
    // to a different authentication server. This is for a very
    // particular use case that comes up when implementing a oauth
    // server. Unsupported and may go away at any point in time.
    //
    // We will eventually provide a general way to use account-base
    // against any DDP connection, not just one special one.
    Accounts.connection = DDP.connect(
      __meteor_runtime_config__.ACCOUNTS_CONNECTION_URL)
  }
}

但是,我能够通过设置$ MONGO_URL环境变量来使用我的数据库(我认为它设置了帐户包使用的默认连接):

在一个终端窗口中,我在端口27017上启动了mongo

> mongod

在另一个窗口中,我设置了MONGO_URL并添加了相应的包,然后启动了流星:

> export MONGO_URL=mongodb://localhost:27017/test
> meteor add accounts-base
> meteor add accounts-password
> meteor

最后,在我的浏览器控制台中,我创建了一个帐户:

> Accounts.createUser({username: 'me', password: 'guest'});

然后我在我的mongo实例中连接到test数据库:

> mongo
  MongoDB shell version: 3.0.1
  connecting to: test
> db.users.find()
  { "_id" : "L3EDrS8FnRymDLhPp", ... "username" : "me" }

简而言之,我认为你有三个不太棒的选择:

  • 使用MONGO_URL环境变量(可能是最佳选项)
  • 破解基于帐户的程序包以执行您想要的操作
  • 尝试不受支持的ACCOUNTS_CONNECTION_URL变量,该变量可能会在任何时间点消失“