garima
garima

Reputation: 5244

Unable to connect remote Mongo DB via meteor app

I am trying to connect remote DB from meteor app on my machine using the following code in js file:

if(Meteor.isServer){
    Meteor.startup(function () {
       var myDatabase = new MongoInternals.RemoteCollectionDriver("http://172.22.77.134:27017");
       MyCollection = new Mongo.Collection("euro2012", { _driver: myDatabase });
     });
   }

The following error is thrown:

Error: EACCES, unlink '/home/garima/my_cool_app/.meteor/local/build-garbage-e7yeel/README' at Object.Future.wait (/home/garima/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/lib/node_modules/fibers/future.js:326:15) at Object.wrapper [as unlink] (/home/garima/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/tools/files.js:1124:24) at Object.files.rm_recursive (/home/garima/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/tools/files.js:262:13) at /home/garima/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/tools/files.js:258:15 at Array.forEach (native) at Function..each..forEach (/home/garima/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/lib/node_modules/underscore/underscore.js:79:11) at Object.files.rm_recursive (/home/garima/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/tools/files.js:256:9) at Object.files.renameDirAlmostAtomically (/home/garima/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/tools/files.js:690:11)

After using sudo I get the following error:

(STDERR) W20150225-14:20:26.847(5.5)? (STDERR) /home/garima/.meteor/packages/meteor-tool/.1.0.40.1ef5dzv++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:173 W20150225-14:20:26.847(5.5)? (STDERR) throw(ex); W20150225-14:20:26.848(5.5)? (STDERR) ^ W20150225-14:20:26.891(5.5)? (STDERR) Error: URL must be in the format mongodb://user:pass@host:port/dbname W20150225-14:20:26.891(5.5)? (STDERR) at Error () W20150225-14:20:26.891(5.5)? (STDERR) at exports.parse (/home/garima/.meteor/packages/mongo/.1.0.11.pnwx20++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/connection/url_parser.js:15:11) W20150225-14:20:26.891(5.5)? (STDERR) at Function.MongoClient.connect (/home/garima/.meteor/packages/mongo/.1.0.11.pnwx20++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/mongo_client.js:164:16) W20150225-14:20:26.891(5.5)? (STDERR) at Function.Db.connect (/home/garima/.meteor/packages/mongo/.1.0.11.pnwx20++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/db.js:2035:23) W20150225-14:20:26.891(5.5)? (STDERR) at new MongoConnection (packages/mongo/mongo_driver.js:151:1) W20150225-14:20:26.892(5.5)? (STDERR) at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:1) W20150225-14:20:26.892(5.5)? (STDERR) at app/my_cool_app.js:26:25 W20150225-14:20:26.892(5.5)? (STDERR) at /home/garima/my_cool_app/.meteor/local/build/programs/server/boot.js:212:5

Upvotes: 2

Views: 747

Answers (1)

Tarang
Tarang

Reputation: 75975

You have more than one issue. The error stopping your app from running is caused by insufficient permissions when you ran your app. Perhaps you ran it with sudo once?

To fix that simply make sure you have permissions to all the files in your project.

The other is you're using a http url instead of a mongo url when you define new MongoInternals.RemoteCollectionDriver. A Mongo URI looks something like this

mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

The full docs on the uri can be found here

Use this URI format instead of the http one to solve this issue (unrelated to the permission issue).

Upvotes: 3

Related Questions