简体   繁体   中英

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

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();

doc reference for the find function: 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,

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

where collection is of type IMongoCollection .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM