"fullNames" is a list of strings that I want to search for in a database with the 2 tables "FistName" and "LastName". But this code returns the error: "Unable to determine the serialization information for u => (u.FirstName u.LastName)."
var filter = builder.In(u => u.FirstName u.LastName, fullNames);
var task = _db.GetCollection<Models.User>(Models.CosmosDb.Collections.Users)
.Find(filter)
.ToListAsync();
var users = await _asyncRetryPolicy.ExecuteAsync(() => task);
Tried to replace the first line with this, but with the same result:
var filter = builder.In(u => $"{u.FirstName}{u.LastName}", fullNames);
What am I doing wrong?
CodePudding user response:
The driver expects a lambda expression that evaluates to a simple property as parameter for In
. In the sample, the lambda expression concatenates two properties, hence the error.
Instead of using a Find
, you could use Aggregate
. This offers more options when querying and reshaping the data.
In this sample, the first stage would be a $set
stage that concatenates the first and last name of the document. In a subsequent $match
stage, you can include the $in
condition and filter the data.
From a performance perspective, it would be best if you store the full name with the documents. Then you only need a simple filter that can also use an index.