27 Feb 2016

Shared DB Access and User Authentication with Meteor

These are notes on accessing a MongoDB from two Meteor apps as well as sharing User authentication between multiple apps.

Sharing the Same Database

Option #1 - There's a brief Stackoverflow discussion on this. Start the main app that owns the database:


The database is now accessible on port 3001.
Start the second app, pointing it at the first apps DB:

MONGO_URL="mongodb://localhost:3001/meteor" meteor --port 3002

Accessing a Collection from Another DB

Option #1 -

There's a good post on this here (Mar 2015). Start the main application DB.


Setup access to the user collection from the second application:

var database = new MongoInternals.RemoteCollectionDriver(
MyCollection = new Mongo.Collection("Users", { _driver: database });

Option #2 -

From this Stackoverflow post (Aug 2013):

var remote = DDP.connect('http://server1.com/');
Items = new Meteor.Collection('items', remote); 

remote.subscribe('items', function() {
  var items = Items.find();
  console.log(items.count());  // get 1         

Logging In Using Another App

From this Stackoverflow post (Nov 2013):

var DDPConnection = DDP.connect();

DDPConnection.call("login", {"password":"qwerty",
    "user" : { "email":"email@email.com" }
    function(err,result) {
        //Check result

DDP Connect

DDP connect is documented here.