I'm using C# MongoDb.Driver(2.10) to get a document from a collection :
MongoClient dbClient = new
MongoClient("mongodb://***");
IMongoDatabase db = dbClient.GetDatabase("***");
var collection = db.GetCollection<BsonDocument>("***");
Console.WriteLine( collection.Find(Builders<BsonDocument>.Filter.Empty).First());
This does work and emits this :
So everything is OK.
But now I want to try to filter where lockPolicyId.ToString()=="1" .(As a string , not as a number)
So I've tried :
var filter= Builders<BsonDocument>.Filter.Where(a=>a["lockPolicyId"].AsString=="1");
var t=collection.Find( filter ).First() ;
Console.Writeline(t);
Which shows this error :
The operands for operator 'Equal' do not match the parameters of method 'op_Equality'.
I've also tried:
var filter= Builders<BsonDocument>.Filter.Where(a=>a["lockPolicyId"].ToString()=="1");
And got this error:
{document}{lockPolicyId}.ToString() is not supported.
Now, I do understand why it's happening ( Int and not String).
But still
Question:
How can I filter by the ToString value?
In other words, to make this line works:
Builders<BsonDocument>.Filter.Where(a=>a["lockPolicyId"].AsString=="1")
