MongoDB - Meteor 1.4 32-bit deprecated is an issue?; Using MONGO_URL

Thanks so to recap where do i find the url setting for the mongodb of the given app? Is it in a config file? As i’d rather not use the command line. I will try to install a 64 bit mongo locally and point meteor to use that one.

If you install it on your local dev machine, it will be `mongodb://localhost:27017" by default.

Meteor dev defaults to a database name of meteor by default, but I suggest explicitly specifying the name as in my first reply, so something like mongodb://localhost:27017/database_name.

MongoDB has a configuration file, which you can edit if you need to change things like the port number.

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

2 Likes

That i realised it has two db’s ‘local’ and ‘meteor’ . But how do i make a meteor app Point to the separately installed MongoDB? Would meteor locate the informaiton from that mongo configuration file?

Ah - no - you need to set it as an environment variable.

1 Like

Is there a way to run two meteor applications, have them speak to one instance of mongo (share collections), all at the same time on your local box?

Yes - you just need to run each application on a different port.

2 Likes

Thanks. I’d run meteor like so: meteor --port 3030

I also have to specify the mongo URL like so: mongodb://localhost:27017/database_name? If so, where does this go?

you would do …

after running your meteor app in command prompt

you set the following environment variables in both apps as follows :

$ MONGO_URL=mongodb://x.x.x.x:xxxxx/myappdb

if you want to test more than one app in tandem on the same machine out you would specify a different port number when running it from command prompt like so …

meteor --port 8000

When you don’t specify a port number it defaults to 3000. …

Cheers

1 Like

you could do it via command prompt inside the meteor if you are on windows (assuming you’re admin))

set MONGO_URL=mongodb:pornumber/database_name

then run meteor

1 Like

Thank you @metrophobe. I’m on macOS by the way.

So where is MONGO_URL=mongodb:portnumber/databasename actually stored, locally on my dev box, and on the server? In a settings.json file for example?

On dev, I use package.json:
"scripts": { "dev": "MONGO_URL=mongodb://localhost:27017/your_db_name meteor --settings settings.json" }

and then, instead of meteor, you just: npm run dev
( the --settings settings.json is optional, to include other options )

On the server-side: it depends on how you deploy. If you use MUP, you can specify it in mup.json

1 Like

@eleventy

Right now I start meteor like so:

meteor --settings .config/development/settings.json

but my settings.json file doesn’t have a ‘scripts’ tag within it. This file is used for my private/public app settings.

Could I just add the following to my existing settings.json file and have it work locally?

 "dev": "MONGO_URL=mongodb://localhost:27017/your_db_name"

Nope. It goes into package.json, the npm package file

Hi there,

Read your post in my other thread which is totally unrelated to what you are trying to accomplish here. Just to clarify how settings (settings.json) and startup (package.json) scripts work.

settings.json is there primarily to allow you to put in config settings that are spread application-wide (if needed). Setting them as private makes them available to the server whereas setting them as public makes them available both to client and server. By default they are only available to the server. Note that these are made available AFTER the app starts running. And I am starting to think that MONGO_URL cannot be modified dynamically after startup (but that’s just me). In order to force your app to use the settings you have to run your meteor app with the following command.

meteor --settings settings.json

Now package.json is an optional file (which sits in the root of your app. It might not be there so you would have to create it). package.json is YAJF which gives you the facility to put in start-up scripts BEFORE the app runs. A sample for your scenario is shown below:

{
  "name": "yourappname",
  "scripts": {
  "start": "MONGO_URL=mongodb://localhost:27017/meteorprojectname meteor --port 5000"
}

Since meteor is built on-top of NodeJS you can then make use of npm to locate this package.json and start the related script. You could have multiple scripts but since mine is called ‘start’ you would invoke the config script start via npm inside your project folder like so…

npm start

Notwithstanding all this, what I was trying to do was to change process.env (environment variable) inside Meteor.onStartup() and this is different from what you required.

Hope this helps.

2 Likes

This worked out great mate, thanks!

You are most welcome!

I can use my MONGO_URL without issues, but when I try to put my MONGO OPLOG inline, it doesn’t work:

MONGO_OPLOG_URL=mongodb://oplog-reader:password@dsserverid-a0.mlab.com:port,dsserverid-a1.mlab.com:port/local?replicaSet=rs-dsserverid&authSource=admin

So this works:

"scripts": {
    "start": "MONGO_URL=mongodb://username:password@dsserverid-a0.mlab.com:port,dsserverid-a1.mlab.com:port/databasename?replicaSet=rs-dsserverid meteor --settings .config/development/settings.json"
}

But this doesn’t:

"scripts": {
    "start": "MONGO_URL=mongodb://username:password@dsserverid-a0.mlab.com:port,dsserverid-a1.mlab.com:port/databasename?replicaSet=rs-dsserverid MONGO_OPLOG_URL=mongodb://oplog-reader:password@dsserverid-a0.mlab.com:port,dsserverid-a1.mlab.com:port/local?replicaSet=rs-dsserverid&authSource=admin meteor --settings .config/development/settings.json"
}

Why?

So I’ve installed mongodb for server 64 bit since windows would get 64 bit by default, and set mongo url, but it won’t connect.

Should I start up mongodb first since it’s not running in background or anything?

Yes - MongoDB has to be running if you’re using a separate installation.

https://docs.mongodb.com/v3.0/tutorial/getting-started-with-the-mongo-shell/

Is still tricky with windows 10 not that it’s working for me.