Convert MongoDB BsonDocument to valid JSON in C#

后端 未结 10 2570
旧巷少年郎
旧巷少年郎 2020-12-01 14:16

I am working with the MongoDB C# driver. I have a BsonDocument with some data which includes some MongoDB-specific types (like ObjectIDs and ISODates). I want t

10条回答
  •  北海茫月
    2020-12-01 14:51

    Here is the way i did it, to skip mongodb _id entry.

    var collection = _database.GetCollection("test");
    
    var result = await collection.Find(new BsonDocument())
         .Project(Builders.Projection.Exclude("_id"))
         .ToListAsync();
    var obj = result.ToJson();
    

提交回复
热议问题