MongoDB Atlas Search using mongo-java-driver

Hi,

Currently I am using atlas search for search use case in my java application. I have gone through the aggregation pipeline functionality provided in the java SDK and found that there isn’t a support for $search operator in the SDK(Aggregates.java) like there is a support for $match, $project and so on. I have done one experiment using java code to create BSON documents with required hierarchy maintained and passed it to aggregation pipeline like coll.aggregate(Arrays.asList(new Document("$search", value))). Using this approach things are working as expected. I just want to know on below things,

  1. Is this the right/recommended approach to support search functionality using this driver for Atlas Search?
  2. I even didn’t find the Atlas Search index creation using mongo-java-driver so is there a way to do this using java driver as well?

Do let me know what else information is needed from my end.

Hi @Sachin_Havinal and welcome in the MongoDB Community :muscle: !

You are correct. There is no helper for this stage, yet. So your current approach is the correct one until we have one.

You will have to make your own little helper in the meantime. :slight_smile:

That being said… The Java Driver is open source and we love new contributors. :wink:

Cheers,
Maxime.

Hello there,
In version 4.7.0 the Java driver added a new builder for Atlas search. Please give it a try.

Thank you!
Rachelle

1 Like

Hello all,
Could you give an example of how to use it, or where I could find the documentation?

Hi Alejandro,

Have a look at this link from Spring Data MongoDB – the section titled “10.12.2 Supported Aggregation Operations” includes a tip on how to use $search with Spring Data MongoDB.