【问题标题】:mongoDB C# Driver is not returning any datamongoDB C#驱动程序没有返回任何数据
【发布时间】:2017-04-23 00:23:24
【问题描述】:

我遇到了一个问题,即 C# 驱动程序没有使用 async-await同步 方法返回任何数据。

当尝试在命令行中运行时,它可以完美运行,这里是sn-p:

db.Collection_StudentResults.aggregate([ { $unwind: "$modules" }, { $match: { "studentNumber": "", "modules.code": "" } } ])

这是我在 C# 中的设置方式:

public static async Task<BsonDocument> getSingleStudentData(string studentNumber)
    {
        var client = new MongoClient("mongodb://localhost:27017");
        var db = client.GetDatabase("dbStudents");
        var collection = db.GetCollection<BsonDocument>("Collection_StudentResults");

        var aggregate = collection.Aggregate()
            .Unwind("modules")
            .Match(new BsonDocument { { "studentNumber", studentNumber } });

        var result = await aggregate.ToListAsync();

        return result.FirstOrDefault();
    }

使用的驱动程序:v2.4.0 MongoDB 版本:v3.2.10

Collection_StudentResults中,第一个文档包含studentNumbermodules数组,modules数组中每个文档有 code 字段。

请帮忙! 谢谢

【问题讨论】:

    标签: c# mongodb driver document bson


    【解决方案1】:

    对不起-我的错,糟糕的糟糕......

    我错过了构建器脚本中的 db = db.getSiblingDB - 这导致数据进入根数据库。

    一切顺利。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-15
      • 1970-01-01
      • 2013-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多