when i create a filter with eg.
filter := bson.D{
{Key: consts.DaoReference, Value: reference},
{Key: consts.DaoVersion, Value: bson.M{“$gt”: int32(version)}}}
the driver wraps the query into
{“Reference”:“…”,“Version”:{“$gt”:{“$numberInt”:“0”}}}
i needed {“Reference”:“…”,“Version”:{“$gt”:“0”}} instead - the two query doesn’t response with the same result
The {“$numberInt”:“0”} object is the Canonical Extended JSON encoding for a 32-bit integer. However, data and queries are passed to MongoDB in BSON format. While Extended JSON can be used to represent BSON data, it isn’t literally what is sent to the database.
I have some questions to help me figure out the problem:
Can you provide an example of how you’re using that bson.D filter? For example, are you using it in a MongoDB query like FindOne, or are you trying to marshal it to Extended JSON with MarshalExtJSON?
I didn’t know that it sends different format than I can see in the filter’s debug. I created a separated test for the query and it seems it works perfectly.