【问题标题】:MongoDB C# Drivers to do CRUD operations in Azure cosmos dB EmulatorMongoDB C# 驱动程序在 Azure cosmos dB 模拟器中执行 CRUD 操作
【发布时间】:2018-02-17 15:23:08
【问题描述】:

我正在使用 Azure cosmos dB Emulator 使用 MongoDB C# 驱动程序在 MongoDB 上执行 CRUD 操作。 我能够在模拟器中使用 C# 创建数据库和集合。这是我创建数据库和集合的示例代码..

IMongoDatabase db = dbClient.GetDatabase("<My DB name>");
db.CreateCollection("<Collection Name>");

这些查询工作正常,但是当我尝试将示例数据插入此集合时,它会抛出错误

命令插入失败:处理此请求时发生未知服务器错误..

我插入示例数据的示例代码是

IMongoCollection<UserProfile> collection = db.GetCollection<UserProfile("<Collection Name>");
            UserProfile c = new UserProfile();
            c.ID = 21;
            c.UserName = "<Some Name> ";
            c.Email = "<Email ID>";
            collection.InsertOne(c);

如何使用 MongoDB C# 驱动程序在 Azure cosmos dB 模拟器中执行 CRUD 操作以及如何在模拟器中运行 mongo 查询而不是 SQL 查询? 提前致谢

【问题讨论】:

    标签: c# mongodb-.net-driver azure-cosmosdb


    【解决方案1】:

    模拟器中 MongoDB API 的 UI 尚未实现(虽然即将推出),但其他一切都应该可以工作。您需要为您的用例结合两个教程:

    https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator (在那里寻找 MongoDB 部分)

    https://docs.microsoft.com/en-us/azure/cosmos-db/create-mongodb-dotnet - 构建、运行并确保它适用于模拟器的新连接字符串,然后只需注入您的代码,它就会起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 1970-01-01
      • 2022-10-05
      • 2018-11-13
      • 1970-01-01
      相关资源
      最近更新 更多