我可以使用Test = new Meteor.Collection("testCollection")创建新的流星集合
但是它在我的mongo安装的admin数据库中创建了testCollection。
假设我在mongo中有两个独立的数据库,比如testing,另一个是admin。如何在mongo安装的testing数据库中创建上述集合?
此外,我是否可以在某个地方指定我想要封顶/取消封顶特定的集合,以便定义集合的大小。
发布于 2015-06-04 17:28:20
如果您只想使用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");
}https://stackoverflow.com/questions/30639466
复制相似问题