crud operations posting to "test" database (Cosmosdb/Mongodb - Nextjs with mongoose)

rwkd26 21 Reputation points

I am using Nextjs with mongoose to perform crud operations in my cosmosdb/mongodb database. But when i post or get data they are posted to a database called "test" and not the database i want to. I cant find a solution for changing the destination to where my data is posted. any help?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,264 questions
{count} votes

Accepted answer
  1. Anurag Sharma 17,466 Reputation points

    Hi @@rwkd26 ,

    I was looking into the youtube video link you provided but could not get much out of it. Then there was this link which is having more insight.

    Instead of declaring the entire connection string in 'MONGO_URI' variable can you please create below variables. You can provide the database name which you want to use:

    COSMOSDB_USER = "<Azure Cosmos account's user name, usually the database account name>"  
    COSMOSDB_PASSWORD = "<Azure Cosmos account password, this is one of the keys specified in your account>"  
    COSMOSDB_DBNAME = "<Azure Cosmos database name>"  
    COSMOSDB_HOST= "<Azure Cosmos Host name>"  

    Post this you can use the below code to connect:

    mongoose.connect("mongodb://"+process.env.COSMOSDB_HOST+":"+process.env.COSMOSDB_PORT+"/"+process.env.COSMOSDB_DBNAME+"?ssl=true&replicaSet=globaldb", {  
      auth: {  
        user: process.env.COSMOSDB_USER,  
        password: process.env.COSMOSDB_PASSWORD  
    useNewUrlParser: true,  
    useUnifiedTopology: true,  
    retryWrites: false  

    All this is mentioned in the same article I provided link for.

    Please let me know if this works, or else we can discuss more.

0 additional answers

Sort by: Most helpful