Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-4469

Error when trying to do a atlas search query using java driver

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Export to Language
    • None

      Hi all,
      I'm using the following aggregation query generated from the atlas console to do a simple search query using MongoDB atlas 

       

              testingCollection.aggregate(Collections.singletonList((
                      Filters.eq("$search",
                              Filters.eq("wildcard",
                                      Filters.and(
                                              Filters.eq("path", "name"),
                                              Filters.eq("query", "dushan*"),
                                              Filters.eq("allowAnalyzedField", true)
                                                 )
                                        )
                                )))).first();
      

       

      However, I'm getting the following error

      Exception in thread "main" com.mongodb.MongoCommandException: Command failed with error 8 (UnknownError): 'Remote error from mongot :: caused by :: "path" is required (from "wildcard")' on ****. The full response is {"operationTime": {"$timestamp": {"t": 1603111830, "i": 3}}, "ok": 0.0, "errmsg": "Remote error from mongot :: caused by :: \"path\" is required (from \"wildcard\")", "code": 8, "codeName": "UnknownError", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1603111830, "i": 3}}, "signature": {"hash": ***}, "keyId": ***}}}
      	at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175)
      	at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:302)
      	at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:258)
      	at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:99)
      	at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:500)
      	at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:71)
      	at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:224)
      	at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:202)
      	at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:118)
      	at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:110)
      	at com.mongodb.internal.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:343)
      	at com.mongodb.internal.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:334)
      	at com.mongodb.internal.operation.CommandOperationHelper.executeCommandWithConnection(CommandOperationHelper.java:220)
      	at com.mongodb.internal.operation.CommandOperationHelper$5.call(CommandOperationHelper.java:206)
      	at com.mongodb.internal.operation.OperationHelper.withReadConnectionSource(OperationHelper.java:462)
      	at com.mongodb.internal.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:203)
      	at com.mongodb.internal.operation.AggregateOperationImpl.execute(AggregateOperationImpl.java:189)
      	at com.mongodb.internal.operation.AggregateOperation.execute(AggregateOperation.java:296)
      	at com.mongodb.internal.operation.AggregateOperation.execute(AggregateOperation.java:41)
      	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:190)
      	at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135)
      	at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92)
      	at com.mongodb.client.internal.MongoIterableImpl.first(MongoIterableImpl.java:103)
      	at com.test.App.search(App.java:172)
      	at com.test.App.main(App.java:63)
      
      Process finished with exit code 1
      
      

      I assume that there is an issue with the java driver since when I did a quick debug I found that Filters.and is evaluated as $and, the query that is going to the backend is wrong.
       

      if my approach is wrong could you please point me to the correct documentation or source in which I can achieve the above requirement?

      Thank you,
      Dushan
       

            Assignee:
            Unassigned Unassigned
            Reporter:
            a.dush29@gmail.com Dushan Silva
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: