查看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 环境变量(我相信它设置了默认连接,由 accounts 包使用)来让它使用我的数据库:
在一个终端窗口中,我在端口 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 变量,它可能“随时消失”