user3142695
user3142695

Reputation: 17332

How to use same DB for two ddp connected applications

I have connected two meteor applications via DDP. I expected to get the DB data also on the second service application, but I don't get any data. As both is running on server side I didn't do any subscription - which I think I don't have to in this example.

What am I doing wrong?

  1. Starting main web application: meteor (which should load mongodb on port 3001)
  2. Starting service application: MONGO_URL=mongodb://localhost:3001/mydb meteor --port 3100

Web (main) /server/main.js

Examples = new Mongo.Collection('examples');
var serviceConn = DDP.connect("http://localhost:3100");
console.log(Examples.find().count()); // Returns 21

Service 1 /server/main.js

Examples = new Mongo.Collection('examples');
console.log(Examples.find().count()); // Returns 0 !

So why can't I get the collection data on the service application as it gives me 0 results?

Upvotes: 2

Views: 53

Answers (1)

kkkkkkk
kkkkkkk

Reputation: 7748

Try this in your service application:

const con = DDP.connect('http://localhost:3000');

Examples = new Mongo.Collection('examples', {
  connection: con,
});

console.log(Examples.find().count());

Remember to start your main application first

Upvotes: 3

Related Questions