Mongo DB - Setup as Infrastructure as Code - mongodb

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.

Related

MongoDB Atlas clone entire cluster with database, collections, rules, and functions to a second cluster (Dev/Prod)

I'm new-ish to MongoDB Atlas and I have my dev environment all set up and working with my collections, rules, and some functions in use by HTTPS Endpoints. I'd like to clone all of that into a second cluster on a serverless cluster instance for production.
Is there a best-practice way of doing this and then updating it on an ongoing basis in both directions? Copying functions/endpoints etc from dev to prod, and copying collections from prod to dev?

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

Mongodb replicaset with init scripts in docker-entrypoint-initdb.d

I'm working on trying to get a MongoDB replicaset deployed into Kubernetes with a default set of collections and data. The Kubernetes piece isn't too pertinent but I wanted to provide that for background.
Essentially in our environment we have a set of collections and data in the form of .js scripts that we currently build into our MongoDB image by copying them into /docker-entrypoint-initdb.d/. This works well in our current use case where we're only deploying MongoDB as a single container using Docker. Along with revamping our entire deployment process to deploy our application into Kubernetes, I need to get MongoDB deployed in a replicaset (with persistent storage) for obvious reasons such as failover.
The issue I've run into and found recognized elsewhere such as this issue https://github.com/docker-library/mongo/issues/339 is that scripts in /docker-entrypoint-initdb.d/ do not run in the same manner when configuring a replicaset. I've attempted a few other things such as running a seed container after the mongo replicaset is initialized, building our image with the collections and data on a different volume (such as /data/db2) so that it persists once the build is finished, and a variety of scripts such as those in the github link above. All of these either don't work or feel very "hacky" and I don't particularly feel comfortable deploying these to customer environments.
Unfortunately I'm a bit limited with toolsets and have not been approved to use a cloud offering like MongoDB Atlas or tooling such as the Enterprise Kubernetes Operator. Is there any real supported method for this use case or is the supported method to use a cloud offering or one of the MondoDB operators?
Thanks in advance!

Where does MongoDB Atlas fit in my nodejs app?

I have an express app using MongoDB up and running locally. I am looking at options to deploy and wasn't clear on how MongoDB atlas fit in. I planning on just deploying the express app and database to an ec2 instance. Is that alright? Or do I need a separate instance for mongo to run on? MongoDB Atlas offers M2, M5, M10 etc. as options for nodes. I am very new at backend and want to know if those would be separate from my EC2 instance or if those would be my EC2 instance running my express app for clients to connect to as well.
Mongo Atlas is a standalone hosted MongoDB instance. It's a separate server, or typically a cluster of several servers, that only runs MongoDB. You'd run your Express app on an EC2 instance and have it talk over the network to the Mongo Atlas instance on another server.
The advantage is that you don't have to worry about installing or handholding Mongo, about configuring a redundant Mongo cluster, about upgrades or backups. Generally, separating the database server from the application server also means easier longterm maintenance of both. If your Express server doesn't store any data itself, then it is entirely disposable in case of emergencies, while you can be assured* that the critical data stored in your database is well cared for.
* As far as your contract with Atlas stipulates that the data is being cared for…

MongoDB Cloud Manager Vs Mongodb Atlas

can anyone please give me a high level difference between MongoDB Cloud Manager and Mongodb Atlas. My main aim is to monitor mongodb instances in AWS.
Thanks.
Cloud Manager is used when you want to manage your own infrastructure (you spin up the nodes where MongoDB runs) but still have the benefits of automated backups and monitoring.
Atlas goes one step further by automating everything for you including provisioning the infrastructure. It's a true database as a service fully managed by MongoDB. They hide the complexity of managing servers so all you have to worry about it using MongoDB. It's interesting to note they use AWS (with plans to support Azure and Google) to spin up nodes, perform monitoring, and backups.
The Major difference between Atlas and Cloud manager is that :
Cloud manager is used for monitoring your database deployment and providing the automated back ups in the self hosted environment.
While MongoDB Atlas is used when your deployments are hosted on the MongoDB Servers. So each and ever task is managed by the MongoDB staff. This is basically the database as a service. In case you encounter any issue all you need to open a case with the mongodb and they will help in the investigations of the issue occurred.
Here is an up-to-date answer to this question which explains differences between Atlas, Cloud Manager and also the Ops-Manager:
MongoDB Atlas handles all the complexity of deploying, managing, and healing your deployments on the cloud service provider of your choice (AWS, Azure, and GCP). Atlas pricing details are here 4.
Cloud Manager is a platform for managing MongoDB on the infrastructure of your choice. Cloud Manager pricing details are here 7.
Ops Manager automate, monitor, and back up your MongoDB infrastructure.
Here is the original article and additional resources in the MongoDB community forum: https://www.mongodb.com/community/forums/t/cloud-manager-vs-ops-manager-vs-atlas/42624