Mongo collection Identifier search with filter

To find one item from the mongo collection, I am trying to apply a filter and a collection. But there is a compilation error, as shown below.

enter image description here

This code is taken from official mongodbdocs

var filter = Builders<BsonDocument>.Filter.Eq("_id", id);
var result = _collection.Find(filter);
+4
source share
1 answer

The generic type Buildermust match the generic type of the collection. In your case, the collection should be of type BsonDocument.

var _collection = database.GetCollection<BsonDocument>("name");
var filter = Builders<BsonDocument>.Filter.Eq("_id", id);
var result = _collection.Find(filter);
+6
source

All Articles