jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
287 stars 65 forks source link

update mongo version? (7.0) #264

Closed ghost closed 5 months ago

ghost commented 5 months ago

Anyone maintaining this? Would like to use the percentile operator in the current (7.0) version.

https://www.mongodb.com/docs/manual/release-notes/7.0/#aggregation

jeroen commented 5 months ago

Does this require an update of the C driver?

ghost commented 5 months ago

Does this require an update of the C driver?

https://www.mongodb.com/docs/languages/c/c-driver/current/

If the driver is <= 1.23, I believe so.

jeroen commented 5 months ago

OK I see. I'll try to update it soon then.

jeroen commented 5 months ago

I updated it to 1.26.2. You can install the devel version from https://jeroen.r-universe.dev/mongolite. Can you let us know if it works for you?

ghost commented 5 months ago

No. Using mongolite 2.8.0 r-4.3 windows.

Here's an example from mongo:

# connection: test_db

mongo_data <- fromJSON('[
   { "studentId": "2345", "test01": 62, "test02": 81, "test03": 80 },
   { "studentId": "2356", "test01": 60, "test02": 83, "test03": 79 },
   { "studentId": "2358", "test01": 67, "test02": 82, "test03": 78 },
   { "studentId": "2367", "test01": 64, "test02": 72, "test03": 77 },
   { "studentId": "2369", "test01": 60, "test02": 53, "test03": 72 }]')

test_db$insert(mongo_data)

pipeline <- '[
   {
      "$group": {
         "_id": null,
         "test01_percentiles": {
            "$percentile": {
               "input": "$test01",
               "p": [ 0.95 ],
               "method": "approximate"
            }
         }
      }
   }
]'

test_db$aggregate(pipeline)

output:

Error: unknown group operator '$percentile'
jeroen commented 5 months ago

That looks like a server error? Are you sure your server runs mongodb 7?

jeroen commented 5 months ago

@kevinAlbs @eramongodb do we need to set something in the mongo-c-driver client to enable mongodb-7 APIs?

kevinAlbs commented 5 months ago

Does this require an update of the C driver?

No. I expect the $percentile operator can be used on C driver versions prior to 1.23. Aggregate operators are sent as-is from the driver. Here is an example using the C driver to run the $percentile operator. It was run with C driver 1.22.2 and server 7.0.8. I suggest confirming the server is 7.0.0 or newer.

ghost commented 5 months ago

@jeroen @kevinAlbs

Thanks for all the help. Confirming the server is on 7.0 resolved the issue. Thank's jeroen for the amazingly quick response.

jeroen commented 5 months ago

OK well I updated mongolite anyway to mongo-c-driver 1.26.2, even though that turned out to be not the actual problem..