mongodb - How to create Meteor collection in different database? -
i able create new meteor collection using test = new meteor.collection("testcollection")
but creates testcollection
inside admin
database of mongo installation.
say have 2 separate databases inside mongo testing
, admin
. how create above collection in testing
db inside mongo installation?
moreover can specify somewhere, want cap/uncap particular collection in order define size of collection.
if want use testing
database, can overwrite mongo_url
environment variable before calling app, example (use correct url database):
$ export mongo_url=mongodb://localhost:27017/testing $ meteor
if want use different databases within app, should use the new _driver parameter. use same mongo url default database, replacing database name!
// replace explicit demonstration. static string 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 });
as capped collections, answered in this meteor issue , fixed this commit:
col1 = new meteor.collection("mycollection"); coll._createcappedcollection(numbytes, maxdocuments);
to knowledge, cannot uncap capped collection.
note these methods work, have dissociate collection creations between server , client, since clients cannot access server's databases. in client, create collections usual, same name server version:
if (meteor.isserver) { var testing = new mongointernals.remotecollectiondriver("<mongo url testing>"); test = new mongo.collection("testcollection", { _driver: testing }); test._createcappedcollection(2000000, 500); // capped 2,000,000 bytes, 500 documents } else { test = new meteor.collection("testcollection"); }
Comments
Post a Comment