json - 如何在以下 JSON 值中仅检索状态真或假
问题描述
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 }}
解决方案
试试这个:
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();
推荐阅读
- flutter - 我正在用颤振构建一个照片编辑应用程序,它可以在从图库中挑选的图像上应用内置的照片过滤器
- node.js - 限制用户通过 GET 请求访问 admin 和 _id 详细信息
- spring-boot - 找不到属性 SpringBoot JPA
- python - 我可以用 groupy 和 pandas 计算百分比吗
- angular - 我怎样才能把这个物体以角度的方式放在材料表中
- docker - 在 docker4drupal 中安装 npm 和 gulp
- algorithm - 具有两个自变量的嵌套 for 循环的时间复杂度
- javascript - 为 HTML 视频添加剩余时间
- python - 有人可以解释一下这个 leetcode 字符串操作问题吗?
- pseudocode - 在 Marie.js 中,我将如何为以下伪代码执行 if 语句和循环?