I have a find one and update kind of method in c# for mongodb which gets a collection string
IMongoCollection<TDocument> col = _database.GetCollection<TDocument>(collection);
UpdateDefinition<TDocument> update = new UpdateDefinitionBuilder<TDocument>()
.Set(doc => doc.Session, session);
TDocument? doc = col.FindOneAndUpdate(doc => doc.Field == TempFunction("sometext", doc.AnotherField), update)
Both "Field" and "AnotherField" are string fields of a generic TDocument I suppose the update definition is not important here since the error is related to the expression filter, in particular the first argument of "FindOneAndUpdate" is of type Expression<Func<TDocument, bool>>, the TempFunction method is an example of whenever the findone method throws an error
public static string TempFunction(string text1, string text2)
{
return text1 + text2;
}
In particular the error that the main method throws is
" An unhandled exception has occurred while executing the request. MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: TempFunction("123456789", doc.Email)."
But of course by replacing the "TempFunction" implementation in the third line fixes the error
TDocument? doc = col.FindOneAndUpdate(doc => doc.Field == "sometext" + doc.AnotherField, update)