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?
There is no need for closing the connection explicitly. This way the application avoids creating and closing connections (which is an expensive operation).
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With