Hello,
I am pretty new to MongoDB and to development as a whole, and I am trying to create an app with a development environment which would have a clone of all data (collections & documents) of the production environment.
Is there a process or best practices to set up such a thing?
In my .env.local:
I have set up NODE_ENV to http://localhost:3000 , MONGODB_URI & DATABASE_URL to the local dabatase (mongodb+srv://…/local?..)
Here’s the code of my connection file:
import { MongoClient } from "mongodb";
const uri = process.env.MONGODB_URI;
const options = {
useUnifiedTopology: true,
useNewUrlParser: true,
};
let client;
let clientPromise;
if (!process.env.MONGODB_URI) {
throw new Error("Please add your Mongo URI to .env.local");
}
if (process.env.NODE_ENV === "development") {
if (!global._mongoClientPromise) {
client = new MongoClient(uri, options);
global._mongoClientPromise = client.connect();
}
clientPromise = global._mongoClientPromise;
} else {
client = new MongoClient(uri, options);
clientPromise = client.connect();
}
export default clientPromise;
PS: it’s working perfectly fine when everything is set to the production database.
Now, I get an error such as : (Unauthorized) not authorized on local to execute command
Although I do not understand, as I have a “local” database in MongoDB Compass but on Atlas I can only see the main database.
Thanks in advanced!