Share via

Parameterize MongoDB linked service Database Name in ADF

Dhruv Singla 250 Reputation points
2026-04-24T06:29:28.07+00:00

I have many databases in MongoDB (nearly 20). I need to create linked services for all of them in Azure Data Factory. After creating one, I found that linked services for MongoDB are not parameterized for database name. Is there any way to create a parameterized linked service? I can't create 20 of them.

Screenshot 2026-04-24 at 11.51.57

Azure Data Factory
Azure Data Factory

An Azure service for ingesting, preparing, and transforming data at scale.

0 comments No comments

Answer accepted by question author

AI answer

2026-04-24T06:29:48.3466667+00:00

Yes, the MongoDB linked service database name can be parameterized in Azure Data Factory.

For MongoDB/MongoDB Atlas linked services, the database (or databaseName) property supports expressions, so it can be defined as a parameter instead of a fixed value.

High-level steps:

  1. Open the MongoDB (or MongoDB Atlas) linked service in ADF.
  2. Switch to the Code view (or enable Specify dynamic contents in JSON format under Advanced).
  3. Add a parameters section to the linked service JSON, for example:
       {
         "name": "LS_MongoDb",
         "properties": {
           "type": "MongoDbV2",
           "parameters": {
             "DatabaseName": {
               "type": "String"
             }
           },
           "typeProperties": {
             "connectionString": "<your-connection-string>",
             "database": "@{linkedService().DatabaseName}"
           }
         }
       }
    
    For MongoDB Atlas, use type": "MongoDbAtlas" and "database": "@{linkedService().DatabaseName}".
  4. Save the linked service.
  5. In each pipeline (or dataset) that uses this linked service, supply the appropriate database name value for DatabaseName at runtime.

This way, a single linked service can connect to multiple MongoDB databases by passing different parameter values, avoiding the need to create 20 separate linked services.


References:

AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Smaran Thoomu 35,285 Reputation points Microsoft External Staff Moderator
    2026-04-24T07:55:22.4466667+00:00

    Hi @Dhruv Singla
    Good question - this is a common limitation with MongoDB in ADF.

    For MongoDB linked services, the database name is not fully supported as a dynamic parameter in all cases, especially when using the UI or Key Vault setup. So your observation is correct.

    Here are the practical options:

    Option 1 (recommended): handle it at dataset level

    • Keep one linked service (connection only)
    • Create datasets per database or parameterize the collection/query
    • Pass database-specific values in dataset/activity

    Option 2: separate linked services

    • If database name must change at connection level, then yes - multiple linked services may be required
    • This is the most stable approach today

    Option 3 (advanced / try if needed):

    • You can try parameterizing via JSON (code view), but support is inconsistent for MongoDB
    • Works in some cases, but not guaranteed

    Reference:

    I hope this helps. Let me know your use case - I can suggest the cleanest design for your pipeline.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.