I have objects with 3 string fields Country, Province, City. They can contain null or some string name.
I wanna query all data with the exact same values.
Fo
Depends on the data type of your city variable. If the city variable is of type BsonValue you can use the ?? operator directly:
BsonValue city = null;
var query = Query.EQ("city", city ?? BsonNull.Value);
Console.WriteLine(query.ToJson());
If your city variable is of type string you need an extra conversion cast to make the compiler happy:
string city = null;
var query = Query.EQ("city", (BsonValue)city ?? BsonNull.Value);
Console.WriteLine(query.ToJson());