Olivine-Labs / resty-mongol

Lua MongoDB driver
MIT License
46 stars 23 forks source link

Remove duplicate fields in BSON that break MongoDb 4.0 #14

Closed wglasshusain closed 5 years ago

wglasshusain commented 5 years ago

The col:count() and the authenticate functions use the function attachpairs_start to construct the message to the MongoDb server. This works in our old instance of MongoDb 2.4 but fails in MongoDb 3.x and MongoDb 4.0. Analysis showed that the modified pairs function was duplicating entries e.g.

{ "count": "collectionname", "count": "collectionname", "query":"something" }

This apparently now is prohibited in MongoDb. The col:count() method (for example) silently fails due to MongoDb error message about duplicate BSON field names. (Authenticate also fails with a similar message).

The corrections attached still perform the original intent (as best as I can figure out) of moving the named field to the start of the list, but skip it when encountered again. We were able to successfully call col:count() once this patch was applied.

DorianGray commented 5 years ago

looks good! Sorry it took so long to merge, just had a baby and have been away.