Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait on the client side until connection to mongo on the server side is ready?

Tags:

mongodb

meteor

I have a kind of slow connection between my meteor server and remote mongodb instance. Can I somehow wait on a client side and not register subscriptions until the server is not established connection to mongo?

like image 687
Vladimir Lebedev Avatar asked Nov 22 '12 09:11

Vladimir Lebedev


People also ask

Do you need to close Mongo connection?

There is no need for closing the connection explicitly. This way the application avoids creating and closing connections (which is an expensive operation).

How does MongoDB connect to MongoClient?

Connect to a Single MongoDB Instanceconst MongoClient = require('mongodb'). MongoClient; const assert = require('assert'); // Connection URL const url = 'mongodb://localhost:27017'; // Database Name const dbName = 'myproject'; // Use connect method to connect to the server MongoClient.

How does replica set connect to MongoDB?

To connect to a replica set deployment, specify the hostname and port numbers of each instance, separated by commas, and the replica set name as the value of the replicaSet parameter in the connection string. In the following example, the hostnames are host1 , host2 , and host3 , and the port numbers are all 27017 .


1 Answers

One primitive way of doing this is listening for a change in Meteor.userId() using Meteor.autorun. If you are able to get this, you would know that you have connected to MongoDB. If you are not dealing with authentication, then you could create a method on the server side which returns something from MongoDB. When it returns something, on success in the client side you could start all of the subscriptions.

like image 90
HGandhi Avatar answered Oct 20 '22 21:10

HGandhi