Closed christiangroth closed 5 years ago
Thanks @christiangroth
IMO we have to stay compatible with MongoDB 3.x, at least with 3.4 and 3.6. I need @ujibang to comment on this, because I don't know why the countDocuments
method was introduced. This would be a breaking change and should be put into a major release, so can I imagine it was introduced by mistake?
the countDocuments() methods was introduced in MongoDB java driver v 3.8
RESTHeart works (i.e. all integration tests pass) also with mongodb 3.4 and 3.6.
I also explicitly tested the count requests on MongoDB 3.4 without problems.
The exception you get is:
java.lang.NoSuchMethodError: com.mongodb.client.MongoCollection.countDocuments(Lorg/bson/conversions/Bson;)
This means that you are using an old (version< 3.8) MongoDB driver .
It is safe to use latest driver versions with MongoDB 3.4. Check the driver compatibility matrix
@ujibang this one fixed it. I upgraded to driver-version 3.9.1 and it works with MongoDB 3.4. Thanks!
While developing a pull request I'm using the latest master Branch version 3.9.0-SNAPSHOT and I expected some trouble with our application. We are using the count method on collections and get the following exception:
2019-03-15 07:33:45.453 [XNIO-1 task-4 / 7378115bcb1d5ba5] ERROR io.undertow.request - UT005071: Undertow request failed HttpServerExchange{ GET /MithrasEnergy20/locations request {X-Real-IP=[10.156.0.17], accept-encoding=[gzip, deflate, br], dnt=[1], origin=[https://caas-webapp.caas-741.planet-express.e-spirit.com], X-Scheme=[https], Connection=[close], X-Forwarded-Port=[443], X-Forwarded-For=[10.156.0.17], cookie=[_dy_csc_ses=t; _dy_soct=245650.369141.1547016017; _dyjsession=00c0d11c429d2d918b8e18283261a5dc], referer=[https://caas-webapp.caas-741.planet-express.e-spirit.com/], no-auth-challenge=[true], Host=[caas.caas-741.planet-express.e-spirit.com], X-Forwarded-Host=[caas.caas-741.planet-express.e-spirit.com], accept=[application/json, text/plain, */*], accept-language=[de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7], user-agent=[Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36], authorization=[Basic YWRtaW46OHg0PTMyRHVkZQ==], X-Forwarded-Proto=[https], X-Original-URI=[/MithrasEnergy20/locations?count&pagesize=0], content-type=[application/json]} response {Auth-Token=[5ua3ge19uv7osy522f06e5p1ank376edu3rsvrhu1yblwx0mn7], Access-Control-Allow-Origin=[https://caas-webapp.caas-741.planet-express.e-spirit.com], X-Powered-By=[restheart.org], Auth-Token-Valid-Until=[2019-03-15T07:48:45.440Z], Auth-Token-Location=[/_authtokens/admin], Access-Control-Allow-Credentials=[true], Access-Control-Expose-Headers=[Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By]}} java.lang.NoSuchMethodError: com.mongodb.client.MongoCollection.countDocuments(Lorg/bson/conversions/Bson;)J at org.restheart.db.CollectionDAO.getCollectionSize(CollectionDAO.java:133) at org.restheart.db.DbsDAO.getCollectionSize(DbsDAO.java:468) at org.restheart.handlers.collection.GetCollectionHandler.handleRequest(GetCollectionHandler.java:83) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.handlers.metadata.TransformerHandler.handleRequest(TransformerHandler.java:78) at org.restheart.handlers.RequestDispatcherHandler.handleRequest(RequestDispatcherHandler.java:562) at org.restheart.handlers.injectors.CollectionPropsInjectorHandler.handleRequest(CollectionPropsInjectorHandler.java:107) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.handlers.injectors.DbPropsInjectorHandler.handleRequest(DbPropsInjectorHandler.java:92) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.handlers.injectors.AccountInjectorHandler.handleRequest(AccountInjectorHandler.java:56) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.security.handlers.AccessManagerHandler.handleRequest(AccessManagerHandler.java:61) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.security.handlers.AuthTokenInjecterHandler.handleRequest(AuthTokenInjecterHandler.java:78) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:54) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:55) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:61) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:96) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.security.handlers.SecurityHandler.handleRequest(SecurityHandler.java:76) at org.restheart.security.handlers.SecurityHandlerDispacher.handleRequest(SecurityHandlerDispacher.java:62) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.handlers.injectors.BodyInjectorHandler.handleRequest(BodyInjectorHandler.java:277) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.handlers.OptionsHandler.handleRequest(OptionsHandler.java:58) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.security.handlers.CORSHandler.handleRequest(CORSHandler.java:88) at org.restheart.handlers.RequestLoggerHandler.handleRequest(RequestLoggerHandler.java:84) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.handlers.TracingInstrumentationHandler.handleRequest(TracingInstrumentationHandler.java:39) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.handlers.MetricsInstrumentationHandler.handleRequest(MetricsInstrumentationHandler.java:59) at org.restheart.handlers.PipedHttpHandler.next(PipedHttpHandler.java:131) at org.restheart.handlers.injectors.RequestContextInjectorHandler.handleRequest(RequestContextInjectorHandler.java:691) at org.restheart.handlers.injectors.RequestContextInjectorHandler.handleRequest(RequestContextInjectorHandler.java:696) at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:91) at io.undertow.server.handlers.HttpContinueAcceptingHandler.handleRequest(HttpContinueAcceptingHandler.java:83) at org.restheart.handlers.ErrorHandler.handleRequest(ErrorHandler.java:70) at io.undertow.server.handlers.encoding.EncodingHandler.handleRequest(EncodingHandler.java:72) at org.restheart.handlers.GzipEncodingHandler.handleRequest(GzipEncodingHandler.java:75) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:364) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830) at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377) at java.lang.Thread.run(Thread.java:748)
This is totally fine for our current situation because we're using MongoDB version 3.4 and plan to upgrade to version 3.6 soon. Regarding your documentation on https://restheart.org/learn/setup/ everything should be fine using MongoDB 3.6.
A quick look at the MongoDB API shows that the used countDocuments method was introduced in MongoDB 4.0, prior there is only the count method.
So I'm not sure if your documentation is correct or you require MongoDB 4.0. Unfortunately there is no clear statement about the required minimum MongoDB version.
The change was introduced in RH 3.6.0: https://github.com/SoftInstigate/restheart/commit/4e0cca9856c68a5f18fb82fb804e0e88d5a4740b#diff-52a6125578bb0e439141c8cf0c2ed7e6
Thanks for your feedback, Christian