Create custom domain with mongoDB atlas using CNAME record - mongodb

I am setting up a mongoDB cluster on mongoDB atlas.
To connect to the cluster you get an URL like cluster-01.mongodb.net. For convenience reasons I tried to set up a CNAME record on AWS Route53 pointing from cluster-01.my-company.co to the mongoDB cloud URL above.
When connecting to the cluster:
mongo "mongodb+srv://mongo-01.my-company.co/test" --username user
But I am getting the following error:
DNSHostNotFound: Failed to look up service "_mongodb._tcp.mongo-01.my-company.co": Undefined error: 0
Has anyone experiences in setting up a CNAME record for a mongoDB cloud cluster?

This is not possible. See https://jira.mongodb.org/browse/CDRIVER-2556 and in particular this commit https://github.com/mongodb/specifications/commit/3c1ff124ce47fa7b5d97b336028e575efd0e3d1e , which specifically disallows using CNAME with mongo+srv.

Currently, mongo atlas doesn't have such feature. If your requirement is to update your cluster name and if it is okay to have a little downtime, Use mongo atlas live migration service to migrate it to a different cluster(with the new name) using the following link, cutover to stop migration once migration is done and use new cluster.
https://docs.atlas.mongodb.com/import/live-import/
In case, if you want to have this feature in upcoming releases of mongo atlas, There is a request for this feature in the mongo feedback portal.
https://feedback.mongodb.com/forums/924145-atlas/suggestions/40474783-allow-custom-dns-hostnames-to-be-added-to-cluster
Also, this live migration service supports upgrading the mongo cluster version in atlas with minimal downtime.

Related

how is possible create database inside existing cluster with Mongo atlas api endpoint?

how is possible create database inside existing cluster with Mongo atlas api?
I'm trying to use POST /groups/{GROUP-ID}/databaseUsers but didn't work.
https://www.mongodb.com/docs/atlas/reference/api/database-users-create-a-user/
The MongoDB Atlas API is for programmatic access to Atlas' management, monitoring, and backup features. API connections are to the Atlas service, not to the underlying MongoDB clusters.
The same problem in https://dba.stackexchange.com/questions/226070/mongo-atlas-api-get-databases-and-collections-in-a-cluster

Mongo DB - Setup as Infrastructure as Code

We are in the process of creating a new Database using Mongo DB Atlas and we are checking the possibility of setting up the entire setup (Project, Cluster, Database, Collections, Users etc.) using Infrastructure as Code. This will enable us to setup a new environment easily using the scripts. We saw few options like Terraform Templates (https://docs.mongodb.com/mongodb-vscode/create-cluster-terraform/). But this will setup only the project, cluster and database users. We do not see a way in setting up databases or collections. Is there any documentation or guidance around how to spin up Mongo DB using IaC?
The following is the mongodb atlas terraform provider: https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/database_user this can be used to interact with the resources supported by MongoDB Atlas.
There you can check all the available provider resources and data sources.

MongoDB Atlas Replica Set

I am using MongoDB as my primary database with the Mongoose ODM. I am dealing with some database transactions and the only way to do achieve DB Transactions in MongoDB is to use replicaSets. I was able to achieve this in development mode using the run-rs package. However, in production mode, from the MongoDB docs using replicaSets requires that I set up k8s object with Atlas. But I am just a beginner at containers and orchestration. I tried learning about Docker, is it possible to setup a service that could run this replicaSets from docker? And is there any easier way I could setup replicaSets with MongoDB Atlas?
Thanks.
You can set up a one node replica set for development and testing.

What is the correct MONGO_URL setting for replica sets on Meteor 1.4.1.1

This morning I went to deploy my updated Meteor project onto Heroku.
I was upgrading from 1.1.0.3 to 1.4.1.1.
Using the Meteor Buildpack Horse everything installed correctly, but the application was erroring out with the error;
MongoError: seed list contains no mongos proxies, replicaset connections requires the parameter replicaSet to be supplied in the URI or options object, mongodb://server:port/db?replicaSet=name
My MONGO_URL was mongodb://u:p#url1:port,url2:port/db so I changed it to;
mongodb://u:p#url1:port,url2:port/db?replicaSet=set-name
If I made a mistake with the replicaSet param I would get this error;
MongoError: no primary found in replicaset
Which seems sensible, since the replicaset didn't exist, but when I put the correct value in I get that original error again saying the seed list contains no proxies.
My replica set has a dash in the name, I don't know if that is relevant.
What I've tried
I've tried using the URL that throws this error in a Mongo client and it allows me to connect to the instance fine, so I know all the details are correct.
I've also tried escaping the replicaSet, so ?replicaSet=set\-name this gave me the MongoError: no primary found in replicaset error.
I have an open ticket with my MongoDB provider, but I suspect this is a Meteor/me issue!
Meteor v1.4 uses a new version of the MongoDB driver.
While the MONGO_URL environment variable was in the correct form, the error was caused by MONGO_OPLOG_URL, which should be modified to include a replicaSet argument.
See this GitHub issue for more details and the following notes (regarding Compose.io).
From the oplog driver documentation:
Oplog tailing is automatically enabled in development mode with meteor run, and can be enabled in production with the MONGO_OPLOG_URL environment variable.
(...)
To use oplog tailing in your production Meteor app, your MongoDB servers must be configured as a replica set; a single-mongod database has no oplog. Your cluster may not use Mongo sharding.
And the migration guide:
As of 1.4, you must ensure your MONGO_OPLOG_URL contains a replicaSet argument (see the changelog and the oplog documentation).
NOTE: Some MongoDB hosting providers may have a deployment setup that doesn't require you to use a replicaSet argument. For example, Compose.io has two types of deployments, MongoDB Classic and MongoDB+. The new MongoDB+ offering is a sharded setup and not a true replica set (despite the shard being implemented as a replica set) so it does not require the replicaSet parameter and Meteor will throw an error if you add it to your connection strings.

deploying mongodb on google cloud platform?

Hello all actually for my startup i am using google cloud platform, now i am using app engine with node.js this part is working fine but now for database, as i am mongoDB i saw this for mongoDB https://console.cloud.google.com/launcher/details/click-to-deploy-images/mongodb?q=mongo now when i launched it on my server now it created three instances in my compute engine but now i don't know which is primary instance and which is secondary, also one more thing as i read that primary instance should be used for writing data and secondary for reading, now when i will query my database should i provide secondary instance url and for updating/inserting data in my mongodb database should i provide primary instance url otherwise which url should i use for CRUD operations on my mongodb database ?? also after launcing this do i have to make any changes in any conf file or in any file manually or they already done that for me ?? Also do i have to make instance groups of all three instances or not ??
Please if any one of you think i have not done any research on this or its not a valid stackoverflow question then i am so sorry google cloud platform is very much new that's why there is not much documentation on it also this is my first time here in deploying my code on servers that's why i am completely noob in this field Thanks Anyways please help me ut of here guys.
but now i don't know which is primary instance and which is secondary,
Generally the Cloud Launcher will name the primary with suffix -1 (dash one). For example by default it would create mongodb-1-server-1 instance as the primary.
Although you can also discover which one is the primary by running rs.status() on any of the instances via the mongo shell. As an example:
mongo --host <External instance IP> --port <Port Number>
You can get the list of external IPs of the instances using gcloud. For example:
gcloud compute instances list
By default you won't be able to connect straight away, you need to create a firewall rule for the compute engines to open port(s). For example:
gcloud compute firewall-rules create default-allow-mongo --allow tcp:<PORT NUMBER> --source-ranges 0.0.0.0/0 --target-tags mongodb --description "Allow mongodb access to all IPs"
Insert a sensible port number, please avoid using the default value. You may also want to limit the source IP ranges. i.e. your office IP. See also Cloud Platform: Networking
i read that primary instance should be used for writing data and secondary for reading,
Generally replication is to provide redundancy and high availability. Where the primary instance is being used to read and write, and secondaries act as replicas to provide a level of fault tolerance. i.e. the loss of primary server.
See also:
MongoDB Replication.
Replication Read Preference.
MongoDB Sharding.
now when i will query my database should i provide secondary instance url and for updating/inserting data in my mongodb database should i provide primary instance url otherwise which url should i use for CRUD operations on my mongodb database
You can provide both in MongoDB URI and the driver will figure out where to read/write. For example in your Node.js you could have:
mongodb://<instance 1>:<port 1>,<instance 2>:<port 2>/<database name>?replicaSet=<replica set name>
The default replica set name set by Cloud Launcher is rs0. Also see:
Node Driver: URI.
Node Driver: Read Preference.
also after launcing this do i have to make any changes in any conf file or in any file manually or they already done that for me ?? Also do i have to make instance groups of all three instances or not ??
This depends on your application use case, but if you are launching through click and deploy the MongoDB config should all be taken care of.
For a complete guide please follow tutorial : Deploy MongoDB with Node.js. I would also recommend to check out MongoDB security checklist.
Hope that helps.