默認情況下,Meteor應用程序可以訪問數據庫中名爲meteor的集合,但我想連接到包含在不同數據庫中的集合。如何連接到流星應用程序中的外部MongoDB集合
環顧四周,我發現了一些片段,其努力做到以下幾點:
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
這意味着你的oplogUrl沒有指向有效的MongoDB oplog源。你有沒有設置一個? – MasterAM
什麼是MongoDB oplog?我必須自己設置它嗎?由於已經有27018上運行的MongoDB服務器,它不應該已經運行了oplog嗎? –
您不必使用oplog(MongoDB用於表示操作並在副本集中使用的格式),但是它的替代方法是使用poll-and-diff。你可以閱讀更多關於它[這裏](http://www.manuel-schoebel.com/blog/meteorjs-and-mongodb-replica-set-for-oplog-tailing)。您可以將數據庫作爲單節點副本集運行,但配置取決於您的MongoDB版本。 – MasterAM