[Solved] Creating two apps with one database

Hi Guys,

I am creating two meteor apps One is an admin app that helps clients (Restaurants) set and run deals, the second is a mobile app that users would have and will receive deals through push notifications. What is the best way to go about this in terms of the apps and database.

My hunch is to build the admin section which would house all the collections and then create another meteor app (The user mobile app) that connects to the admin database (It will not have its own) using DDP.

I have seen solutions that recommends a third party database company like Modulus to host the data and both apps connect

I also know I can build the App and admin section all in the same Meteor app

What is the best way to architect this app that will allow me run it at a decent cost and also give me the provision to switch to native apps later on

Please any insight would be helpful

If it is just a common database, you can point both apps to the same mongodb instance and oplog will take care of the rest.

If you want to reuse some server methods but don’t want to include them in the end ser app’s codebase, you can use ddp connect.

You can also mix the two approaches.

1 Like

Thanks a lot!

Can you recommend a tutorial where I can connect apps to the same database (That is not the local in build one in meteor) all the stuff I am seeing mention using a shell script and I am a little lost

If it is just a common database, you can point both apps to the same mongodb instance and oplog will take care of the rest.

How do you create the collections? Like:

Players = new Mongo.Collection('players', 'mongodb://127.0.0.1:4002/meteor')

No, you create them as you normally would for a single app. But set the
MONGO_URL environment (linux shell environment for the startup script) for
both apps to point at the same mongodb, wherever it is you host the db.

Will this allow my application to update as if it were not just a client application? Eg: when I am using DDP.connect, it seems to intepret my application as a client and use minimongo instead.

Your app connects from its web/mobile client via ddp to a server and uses minimongo for its data requirements. then the server connects to a mongodb server to get/store data.

Now, the client can commect to its own server or another server but as long as it uses the same database, how it works and performs does not differ.

In fact you are alreay using ddp connect anyway, only to a “default” endpoint of your own server.

So there’s no “interpretation” sonce it is all the same.

2 Likes

@adim86 let’s assume you have a mongodb instance running over at mongodb://x.x.x.x:xxxxx

what you should do is, in your app directory, instead of

$ meteor

or

$ meteor run

you do

$ MONGO_URL=mongodb://x.x.x.x:xxxxx/myappdb MONGO_OPLOG_URL=mongodb://x.x.x.x:xxxxx/local --port 3000 meteor run

and that’s it now your app will store its data on that server within a db named myappdb

now if you do the same for another app, using another port like 4000, they both use the same db and if you update something from one app, you’ll see it on the other app immediately as long as your mongodb database has oplog enabled

3 Likes

Awesome that was the answer I was looking for. Because there is no file in meteor during development where I can set the development db (At least i dont know of one) So I was confused how to set this. I have seen some examples say I need to precede the command you showed with ‘export’. What difference does that make?

normally meteor starts a mongodb server dor you if you don’t provide a
custom mongo url like this. and that database is save in your project
folder’s .meteor/local/db folder

if you want a custom db, you use the command I shared

if the complete command is in one line, you don’t need export syntax

but instead of writing that everytime you can set your user environment
variable on the operating system using the export syntax but that’s done
differently on every operating system

Ah ok good to know. I am running a mac, im sure I can google a tutorial on how to set that up

yep, google for “setting up environment variables”

Also, check out this great post by @joshowens.

2 Likes

@serkandurusoy I have used the system you mentioned above (there is some syntax problems like “–port” comes after “meteor” but it worked out great

How do I store this in a file that gets called every time I run the app. Is this a shell file? What will be the command to call if I want this to execute everytime I run meteor. Or do I just put this in my bashrc and give it an alias? I dont know what the “Correct” way to always set these environment variables.

Thanks for all your help

Aliasing would work but if you want flexibility, npm scripts might come in
handy

check these out

http://meteorpatterns.com/Sewdn/project-builds

and

1 Like

This is perfect package.json is exactky what I was looking for!!! awesome!

1 Like