Mongo Go驱动程序Count()方法从Azure CosmosDB中获取“来自服务器的无效响应,值字段不是数字”

I'm using Azure Cosmos DB with MongoDB Api with my project, developed with Golang and MongoDB Go Drivers. When I try to get a count using below code gives the error Invalid response from server, value field is not a number

itemCount, err := myCollection.CountDocuments(ctx, bson.D{{"$and", bson.A{bson.M{"userid": user.ID, "siteid": site.ID}}}})

The same code returns the number of items (in this case 532) when I tried it against a MongoDB database. I then decided to try the same query by writing a simple .Net application, which worked fine with both MongoDB and CosmosDB. Below is the code I used, and it printed 532 for both databases.

var count = database.GetCollection<Model>("myCollection").CountDocuments(filter);
Console.WriteLine(count);

I also tried querying both databases via Robo3T. The query db.getCollection('Consents').count({}) returned 532 from MongoDB while the same query returned NumberLong(532) from CosmosDB.

I wrote this behavior to MSDN forums, but no one relied. I'm not even sure if this is an issue of the database api or the driver. In case of driver, it works with MongoDB and it's what it promised me to do. In case of database api, it works with .Net drivers, and it tells me that Microsoft is well aware of this behavior and finds it acceptable and handles it within its drivers. Anyone have an idea how to overcome this situation?

your filter should be:

itemCount, err := myCollection.CountDocuments(ctx, bson.M{"userid": user.ID, "siteid": site.ID})

bson.M will perform an implicit $and