'Learning Mongodb and having a simple issue with MongoDB
I have the following C# code as I'm learning MongoDB but I get the following error even though this code is straight out of the mongodb documentation! Is there something I'm doing wrong?
The error in visual studio hightlights the "filter" on the last line.
Thanks,
Compiler error
Severity Code Description Project File Line Suppression State
Error CS1503 Argument 1: cannot convert from 'MongoDB.Driver.FilterDefinition<MongoDB.Bson.BsonDocument>' to 'MongoDB.Driver.IMongoQuery
Code snippet
var id = 123921;
var collection = ...GetCollection<CustomerEntity>("Customer");
var filter = Builders<BsonDocument>.Filter.Eq("Customer", id);
var result = await collection.Find(filter).ToListAsync();
Solution 1:[1]
Your problem lies in way of saving your objects. You saved them as MongoDB.Bson.BsonDocument but try to get as CustomerEntity. Due to impossibility to convert from BsonDocument to CustomerEntity you receive this error message. Here I described how you can have CRUD operations in mongodb version 2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |