【问题标题】:How to retrieve only status true or false in below JSON values如何在以下 JSON 值中仅检索状态真或假
【发布时间】:2020-05-27 18:29:30
【问题描述】:
        Console.WriteLine("mongodb localhost connecting...");
        var client = new MongoClient("mongodb://localhost");
        var db = client.GetDatabase("mobtions");                  

        var collection = db.GetCollection<BsonDocument>("AffiliTestStatus");
        var filter = new Dictionary<string, string>();
        filter.Add("offerid", "102030");

        dynamic records = collection.Find(new BsonDocument(filter)).ToList();

这是我从上面的代码中读到的 JSON 响应

{{ "_id" : ObjectId("5e411eca5b7dfc53ac571f71"), "offerid" : "102030", "status" : true }}

【问题讨论】:

    标签: json mongodb c#-4.0


    【解决方案1】:

    试一试:

        var filter = Builders<BsonDocument>.Filter.Eq("offerid", "102030");
        var projection = Builders<BsonDocument>.Projection.Include("status").Exclude("_id");
        var options = new FindOptions<BsonDocument> { Projection = projection };
        var records = collection.FindSync(filter, options).ToList();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 2021-08-08
      • 1970-01-01
      相关资源
      最近更新 更多