简体   繁体   English

如何使用C#在mongodb中将bsondocument转换为没有bson反序列化器的强类型对象

[英]how to convert a bsondocument into a strongly typed object without bson deserializer in monogodb using C#

I'm trying to fetch class object('let it be myObj') with built in find'<'myObj'>'(Filter) function in C# But it returns only bsonDocument我正在尝试使用 C# 中的内置find'<'myObj'>'(Filter)函数获取类对象('让它成为 myObj')但它只返回 bsonDocument

Note: my key and value pair will be dynamic for the filter注意:我的键值对对于过滤器来说是动态的

my Code: List'<'myObj'>' obj = collection.Find(BuilderFilter.Eq("key", "value")).Skip(skipValue).Limit(limitValue).ToList();我的代码: List'<'myObj'>' obj = collection.Find(BuilderFilter.Eq("key", "value")).Skip(skipValue).Limit(limitValue).ToList();

doc reference for the find function: https://api.mongodb.com/csharp/2.0/html/M_MongoDB_Driver_IMongoCollectionExtensions_Find__1.htm find 函数的文档参考: https : //api.mongodb.com/csharp/2.0/html/M_MongoDB_Driver_IMongoCollectionExtensions_Find__1.htm

For finding a document based on a query from MongoDB with C# driver,为了使用 C# 驱动程序根据来自 MongoDB 的查询查找文档,

myObj record = collection.Find(Builders<myObj>.Filter.Eq(x => x.property, valueToLookup)).FirstOrDefault();

where collection is of type IMongoCollection .其中 collection 的类型为IMongoCollection

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用官方 MongoDB C# 驱动程序将 BsonDocument 转换为强类型对象? - How to convert a BsonDocument into a strongly typed object with the official MongoDB C# driver? 如何使用C#从xml获取强类型对象? - How to get a strongly typed object from xml using c#? 如何在不使用foreach的情况下将ArrayList转换为强类型通用列表? - How to convert an ArrayList to a strongly typed generic list without using a foreach? 使用 C# 从强类型类动态构建对象? - Dynamically build an object from a strongly typed class using C#? c#如何dapperRow到网格视图中显示的强类型对象 - c# How to dapperRow to strongly typed object displayed in grid view 如何使用 Linq 在 C# 中找出强类型表是否包含来自另一个强类型表的值 - How can I find out if a strongly typed table contains a value from another strongly typed table in C# using Linq 无法使用C#将对象插入到monogoDB中的集合中 - unable to insert object into collection in monogoDB using c# 如何使用 C# MongoDB 驱动程序编写强类型过滤器,其中嵌套的 object 属性不能相等? - How to do I write a strongly typed filter where nested object properties cannot be equal using C# MongoDB driver? 将 C# object 映射到 BsonDocument - Mapping C# object to BsonDocument C#,将强类型对象作为元素插入XML文档 - C#, insert strongly typed object into XML Document as Element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM