[COMPASS-4469] Error when trying to do a atlas search query using java driver Created: 19/Oct/20  Updated: 01/Jun/22

Status: Open
Project: Compass
Component/s: Export to Language
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Dushan Silva Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File image-2020-10-19-18-18-32-843.png     PNG File image-2020-10-19-18-25-10-938.png    
Story Points: 3

 Description   

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
 



 Comments   
Comment by Durran Jordan [ 20/Oct/20 ]

For text search Compass should generate code like:

 

Filters.text('mongoDB for GIANT ideas', new TextSearchOptions().caseSensitive(true))

Comment by Githook User [ 19/Oct/20 ]

Author:

{'name': 'Durran Jordan', 'email': 'durran@gmail.com', 'username': 'durran'}

Message: JAVA-3868: Update overridden add method javadoc
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/837a77a9eaa7c74b0099c560771b74fc913a81ff

Comment by Githook User [ 19/Oct/20 ]

Author:

{'name': 'Durran Jordan', 'email': 'durran@gmail.com', 'username': 'durran'}

Message: JAVA-3868: Update docs to reflect and filter behaviour
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/8409048f9c0ffbb543e18cd35022ca804f0b60d3

Comment by Cloud GitHub Webhooks [ 19/Oct/20 ]

durran merged a pull request (JAVA-3868 Update docs to reflect and filter behaviour) into the following branch:
master: 837a77a9eaa7c74b0099c560771b74fc913a81ff

Generated at Wed Feb 07 22:36:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.