如果您只想使用testing 数据库,您可以在调用您的应用程序之前覆盖MONGO_URL 环境变量,例如(使用正确的数据库URL):
$ export MONGO_URL=mongodb://localhost:27017/testing
$ meteor
如果您想在您的应用程序中使用不同的数据库,您应该使用the new _driver parameter。只需使用与默认数据库相同的 mongo url,但替换数据库名称!
// this replace is just for explicit demonstration. Static string is advised
var mongo_url = process.env.MONGO_URL.replace("/admin","/testing");
var testing = new MongoInternals.RemoteCollectionDriver(mongo_url);
Test = new Mongo.Collection("testCollection", { _driver: testing });
关于封顶收藏,this meteor issue 已正确回答,this commit 已修复:
col1 = new Meteor.Collection("myCollection");
coll._createCappedCollection(numBytes, maxDocuments);
据我所知,您无法取消以前设置上限的集合。
请注意,要使这些方法起作用,您必须在服务器和客户端之间分离集合创建,因为客户端无法访问您服务器的数据库。在客户端,只需像往常一样创建您的集合,名称与服务器版本相同:
if (Meteor.isServer) {
var testing = new MongoInternals.RemoteCollectionDriver("<mongo url testing>");
Test = new Mongo.Collection("testCollection", { _driver: testing });
Test._createCappedCollection(2000000, 500); // capped to 2,000,000 Bytes, 500 documents
}
else {
Test = new Meteor.Collection("testCollection");
}