2 / 4
Feb 18

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

@David_Nasztanovics thanks for the question!

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?
  • What version of the Go Driver are you using?
  • What version of MongoDB are you using?

Thank you for your answer!

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.

I use v2 driver with mongo 8.0.

Again thanks for your help!