studio
latest
false
- 入门指南
- 设置和配置
- 自动化项目
- 依赖项
- 工作流类型
- 控制流程
- 文件比较
- 自动化最佳实践
- 源代码控件集成
- 调试
- 日志记录
- 诊断工具
- 工作流分析器
- 变量
- 参数
- 导入的命名空间
- 编码自动化
- 基于触发器的 Attended 自动化
- 对象存储库
- ScreenScrapeJavaSupport 工具
- 扩展程序
- Studio 测试
- 故障排除
重要 :
新发布内容的本地化可能需要 1-2 周的时间才能完成。

Studio 用户指南
上次更新日期 2025年12月3日
本教程演示如何从 UiPath 编码自动化连接到 MongoDB Atlas 数据库。MongoDB Atlas 是一项完全托管的云数据库服务,可提供可靠且可扩展的数据库解决方案,且无需进行本地安装。
Here are the ways to implement the MongoDB connection code:
-
Copy and paste the code into a
CSfile of your target project. -
Use a custom activity package and the sample
NUPKGfile
When opting to use the sample
NUPKG file, you have the capability to add the two-factor authentication as an activity within your XAML files.
Tip: Regardless of whether you choose to integrate the MongoDB connection code in your CS files (for coded automations) or XAML files (for low-code automations), remember that you can invoke a coded automation into a low-code one and vice versa. For more information about hybrid automations, visit Creating hybrid automations - Combining Coded and Low-code Workflows.
- Ensure you have UiPath Studio (version 2024.10 or later - recommended).
- Ensure you have a MongoDB Atlas account.
- Install the
MongoDB.DriverNuGet package in your project.- Open your UiPath project in Studio.
- In the Design ribbon, go to Manage Packages.
- Select All Packages or the .NET tab.
- 搜索
MongoDB.Driver。 - Select
MongoDB.Driver, and then select Install. - Accept the license agreement and dependencies.
To use the MongoDB Atlas connection in your coded automation, you can copy and paste the following sample code in a
CS file from your target project. Make sure the namespace of the file matches with the one of your project name.
Note: The sample code connects to MongoDB Atlas using the connection string format specific to cloud deployments. Make sure to replace the placeholder credentials with your actual MongoDB Atlas credentials.
using System;
using System.Collections.Generic;
using System.Data;
using UiPath.CodedWorkflows;
using UiPath.Core;
using UiPath.Core.Activities.Storage;
using MongoDB.Driver;
namespace MongoDBCodedWorkflowsSample
{
public class TestConnection : CodedWorkflow
{
[Workflow]
public string Execute(string username, string password, string cluster)
{
List<string> databaseNames = new List<string>();
try
{
// Create MongoDB Atlas connection string
string connectionString = $"mongodb+srv://{username}:{password}@{cluster}/?retryWrites=true&w=majority";
Console.WriteLine("Connecting to MongoDB Atlas...");
// Initialize MongoDB client
var client = new MongoClient(connectionString);
// List all databases to verify connection
Console.WriteLine("\nAvailable databases:");
databaseNames = client.ListDatabaseNames().ToList();
foreach (var dbName in databaseNames)
{
Console.WriteLine($"- {dbName}");
}
Console.WriteLine("\nConnection successful!");
}
catch (MongoAuthenticationException authEx)
{
Console.WriteLine($"Authentication error: {authEx.Message}");
Console.WriteLine("Please verify your username and password.");
throw;
}
catch (MongoConnectionException connEx)
{
Console.WriteLine($"Connection error: {connEx.Message}");
Console.WriteLine("Please check your network access settings in MongoDB Atlas.");
throw;
}
catch (Exception ex)
{
Console.WriteLine($"MongoDB connection error: {ex.Message}");
throw;
}
return databaseNames;
}
}
}using System;
using System.Collections.Generic;
using System.Data;
using UiPath.CodedWorkflows;
using UiPath.Core;
using UiPath.Core.Activities.Storage;
using MongoDB.Driver;
namespace MongoDBCodedWorkflowsSample
{
public class TestConnection : CodedWorkflow
{
[Workflow]
public string Execute(string username, string password, string cluster)
{
List<string> databaseNames = new List<string>();
try
{
// Create MongoDB Atlas connection string
string connectionString = $"mongodb+srv://{username}:{password}@{cluster}/?retryWrites=true&w=majority";
Console.WriteLine("Connecting to MongoDB Atlas...");
// Initialize MongoDB client
var client = new MongoClient(connectionString);
// List all databases to verify connection
Console.WriteLine("\nAvailable databases:");
databaseNames = client.ListDatabaseNames().ToList();
foreach (var dbName in databaseNames)
{
Console.WriteLine($"- {dbName}");
}
Console.WriteLine("\nConnection successful!");
}
catch (MongoAuthenticationException authEx)
{
Console.WriteLine($"Authentication error: {authEx.Message}");
Console.WriteLine("Please verify your username and password.");
throw;
}
catch (MongoConnectionException connEx)
{
Console.WriteLine($"Connection error: {connEx.Message}");
Console.WriteLine("Please check your network access settings in MongoDB Atlas.");
throw;
}
catch (Exception ex)
{
Console.WriteLine($"MongoDB connection error: {ex.Message}");
throw;
}
return databaseNames;
}
}
}Connection Parameters
- username: The database user you created in MongoDB Atlas
- password: The password for your database user
- cluster: Your cluster hostname from the connection string (e.g.,
cluster0.abc123.mongodb.net)
The sample returns a list of all databases for that specific set of credentials.
Connection String Format - MongoDB Atlas uses the
mongodb+srv:// protocol, which:
- Automatically discovers all nodes in your cluster
- Provides automatic failover support
- Includes retry logic for write operations (
retryWrites=true) - Sets the write concern to majority (
w=majority)
错误处理
- MongoAuthenticationException: Occurs when credentials are incorrect
- MongoConnectionException: Occurs when network access is blocked or cluster is unavailable
- General exceptions: Catches any other MongoDB-related errors
Using a sample
NUPKG file enables you to include the two-factor code in your automations.
- Download the
NUPKGfile. - Upload the downloaded
NUPKGfile to your Orchestrator Host or Tenant feed, which are accessible through your Studio instance. For more information on uploading theNUPKGfile as a custom library to Orchestrator, refer to Manually uploading a library to Orchestrator. - 打开 Studio 项目,然后打开“管理包”菜单。
- Search for the
MongoDB.Coded.Workflows.SampleNUPKGfile you previously saved to your Orchestrator Host or Orchestrator Tenant feed, and install it.Figure 1. Custom library in the Manage Packages menu
- After you install the file, navigate to the Activities panel and locate
MongoDB.Coded.Workflows.Sample. Drag and drop the GetDatabases activity into yourXAMLfiles to test your MongoDB connection and fetch a list of the available databases.Figure 2. GetDatabases activity in the Activities panel