默认情况下,Meteor应用程序可以访问名为meteor的数据库中的集合,但我想连接到不同数据库中包含的集合。
环顾四周,我发现了一些尝试执行以下操作的片段:
var mongoUrl = 'mongodb://127.0.0.1:27018/meteor';
var oplogUrl = 'mongodb://127.0.0.1:27018/local';
var remoteDriver = new MongoInternals.RemoteCollectionDriver(mongoUrl, {
oplogUrl: oplogUrl,
});
var remoteCollection = new Mongo.Collection('extract', {
_driver: remoteDriver,
});
但是这样做我的应用程序崩溃会发出以下错误:
> Exited with code: 8
? (STDERR)
? (STDERR) /Users/test/.meteor/packages/meteor-tool/.1.3.3.ems6rm++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
? (STDERR) throw(ex);
? (STDERR) ^
? (STDERR) Error: $MONGO_OPLOG_URL must be set to the 'local' database of a Mongo replica set
? (STDERR) at Error (<anonymous>)
? (STDERR) at OplogHandle._startTailing (packages/mongo/oplog_tailing.js:216:13)
? (STDERR) at new OplogHandle (packages/mongo/oplog_tailing.js:76:8)
? (STDERR) at new MongoConnection (packages/mongo/mongo_driver.js:216:25)
? (STDERR) at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:16)
? (STDERR) at meteorInstall.collections.job_extract.js (collections/job_extract.js:10:20)
? (STDERR) at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
? (STDERR) at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1)
? (STDERR) at /Users/test/app_meteor/.meteor/local/build/programs/server/app/app.js:1453:1
? (STDERR) at /Users/test/app_meteor/.meteor/local/build/programs/server/boot.js:291:10
? (STDERR) at Array.forEach (native)
? (STDERR) at Function._.each._.forEach (/Users/arj/.meteor/packages/meteor-tool/.1.3.3.ems6rm++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
? (STDERR) at /Users/test/app_meteor/.meteor/local/build/programs/server/boot.js:133:5
答案 0 :(得分:0)
你可以通过在流星应用程序中运行命令来实现 export MONGO_URL = URL。 然后您的应用将连接到URL数据库。