简体   繁体   English

MongoDB C#.NET连接字符串格式

[英]MongoDB C#.NET Connection String Format

I am trying to connect to a MongoDB with my .NET Core 2 controller and I am getting the following error: 我正在尝试使用.NET Core 2控制器连接到MongoDB,但出现以下错误:

MongoDB.Driver.MongoConfigurationException: The connection string 'mongodb://@myapp-a1yri.mongodb.net' is not valid.

I am trying to initialize a MongoClient using the connection string, but I am not sure how to format the connection string and the MongoDB documentation doesn't have anything examples for .NET in it. 我正在尝试使用连接字符串初始化MongoClient,但是我不确定如何格式化连接字符串,MongoDB文档中没有有关.NET的任何示例。

This is my current connection string attempt: var client = new MongoClient("mongodb://@myapp-a1yri.mongodb.net"); 这是我当前的连接字符串尝试: var client = new MongoClient("mongodb://@myapp-a1yri.mongodb.net");

I am sure it is just simple syntax. 我相信这只是简单的语法。

I appreciate the help 感谢您的帮助

I think your @ sign is causing the problem. 我认为您的@符号引起了问题。 Please remove the @ sign from connection string and then try. 请从连接字符串中删除@符号,然后尝试。

var client = new MongoClient("mongodb://myapp-a1yri.mongodb.net")

As I am using without @ sign and it is working fine. 因为我没有@符号使用,并且工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM