Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting the error "The serializer for field ... must implement IBsonArraySerializer" when using AnyIn?

Tags:

c#

mongodb

I declare a Filter in c# by mongodb like this:

var filters = new List<FilterDefinition<Message>>
if (!area.Equals(""))
filters.Add(Builders<Message>.Filter.Eq("Domain", area));

and work perfectly when area is a single string for example 1. but I want area is 1,2,5,55,this filter work. In order to this I have changed my filter to this:

filters.Add(Builders<Message>.Filter.AnyIn(x => x.Domain, area));

according this suggestion

but I got this error :

The serializer for field 'Domain' must implement IBsonArraySerializer and provide item serialization info.

Why am I getting this error and how can I fix it?

I have seen this post but nobody do not answer to this post.

like image 964
Cyrus the Great Avatar asked Oct 20 '25 13:10

Cyrus the Great


1 Answers

If I have understood the question correctly, you shouyld be using the $in query:

   filters.Add(Builders<Message>.Filter.In("Domain", new List<int>() { a1, a2 }));
like image 162
Devesh Avatar answered Oct 23 '25 07:10

Devesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!