Using replica sets in Meteor - mongodb

With Mongoose, you can connect to replica set like so:
mongoose.connect('mongodb://username:password#host:port/database,mongodb://username:password#host:port,mongodb://username:password#host:port?options...' [, options]);
How do you connect to an external MongoDB replica set with Meteor?

You can simply export MONGO_URL with replicaSet configured. And it works pretty well. Make sure to use meteor version 0.6.4 or greater.
See my article for configuring it.

Related

Prisma + MongoDB -> Replica set

Error Invalid "prisma.user.create()". Prisma needs to perform transactions, which requires your MongoDB server to be run as a replica set.
I used Nx (nx.dev) with MongoDB/Express with Prisma.
Apparently, after long hours of facing continuous issues in connecting Prisma and MongoDB(local), we have 3 ways of fixing this.
You have to use either Docker or MongoDB Atlas.
Docker - Docker
MongoDB Atlas - MongoDB Replica
Ps. Your MongoDB URL env should be looking like this -> mongodb://localhost:27017/<your-db-name>?retryWrites=true&w=majority.
I decided to finally choose the option 3.
Jumping from MongoDB to PostgreSQL which don't have any replica issues, but no noSQL :)

Restart MongoDB Replica Set

I tried to search but most of the solutions are very old, and I feel there will be a better solution available which I am unable to find.
Problem
I created the replica set, and it's working. I tried to connect my docker backed application, and it was connecting to it.
Later I changed the dbpath from dbpath=/var/lib/mongodb to the new path dbpath=/data/mongodb. I didn't restart the replica set after this change.
I ran my backend application and it couldn't connect to the replica set. I think its because I didn't restart the MogoDB ReplicaSet. I am using Mongo version 4.4.5
I want to restart the MongoDB Replica Set to check if this can solve the issue.
My connection string :
mongodb://username:pwd#prod-privateIP-1:27017,prod-privateIP-2:27017,prod-privateIP-3:27017/prodDB?replicaSet=replica1&authSource=admin
What is the best practice/recommended approach to restart the MongoDB Replica Set ?

Mongo 3.4 in Meteor

Is that possible to use Meteor with Mongo 3.4 for now? And if so, how to manage that?
I've tried to change packages file, but realised that version of mongo package is not a real Mongo's version.
This is indeed possible by taking care of mongodb yourself instead of letting meteor handle it. To do so you will have to fire up a mongod instance and set the MONGO_URL variable when you run meteor in development mode. In production mode you will be running a standalone mongodb instance anyway, so you will not need to change anything there.
As a reference, see this discussion on the meteor forums: https://forums.meteor.com/t/running-mongodb-3-4-locally-with-meteor/34242
To set an environment variable when running meteor in development mode requires the following:
MONGO_URL=mongodb://localhost:27017/meteor meteor
In this case you are accessing the meteor database (/meteor) on the local mongodb instance (localhost) on the standard port (:27017).

Where to set mongodb start parameter in a meteor application on nitrous.io?

I'm studying meteor and trying some examples on nitrous.io, but the available disk space was soon consumed by the big mongo data files (including the prealloc journal files).
Unfortunately MongoDB is also new to me. I googled around and found that I can start mongoDB with some parameters like --nojournal, but I have no idea where in the nitrous.io app I can pass this parameter to mongodb at startup?
I also can't find any mongodb.conf (even *db.conf) to use the storage.smallFiles setting.
Any help would be appreciated!
Instead of using Meteor's builtin MongoDB instance, you can specify a custom instance (which you can configure the way you want).
To do this Nitrous.IO, you can follow these steps:
Create a box with Meteor template.
Install MongoDB, by running parts install mongodb (Autoparts is Nitrous.IO specific package manager)
Open the MongoDB config located at /home/action/.parts/etc/mongodb.conf
Tweak it to your liking.
Start MongoDB instance by running parts start mongodb
Now you can create a new meteor project - meteor create projectname
Finally, when you're starting meteor on your project specify the MONGO_URL environment variable. eg: MONGO_URL=mongodb://0.0.0.0:27017 meteor.
Hope this would be good enough to get started. You can also upgrade your Nitrous.IO account to increase the storage of your box.
UPDATE: I just noticed that Meteor runs its MongoDB instance with --smallfiles flag set.

Mongo Java Replica Set - Can't find master

I'm having problem with connecting to Mongo Replica Set in production. Replica Set has master on one machine, and secundary + arbiter on other machine.
When I run my application locally it connects and uses Replica Set properly. I'm using Windows OS.
Mongo URI is like this:
mongodb://192.168.2.95:20000,192.168.2.96:20000/testDatabase
I'm using Java Driver 2.10.1.
When I deploy application in production server, It can't use replica set. Error is "can't find master".
When I change mongo URI to use single node, like this:
mongodb://192.168.2.95:20000/testDatabase
then it works!
What's the problem? I have search the web and I found few people with similar problem but I didn't found any proper solution...