Hello, I was finding on the internet how to update all the document field values with lowercase.
I luckily found a query which I modified as per my requirement and it is working correctly.
But now I am trying to convert this query into Java code, I am not able to convert it.
I again started looking into the internet, but couldn’t find any code.
So, can anyone help me convert this query to Java code so that I can use it in my Spring Boot application?
Thanks in advance.
Please use the below code snipped to use the $set operator:
Arrays.asList(new Document("$set",
new Document("recipientEmail",
new Document("$toLower", "$recipientEmail"))
.append("senderEmail",
new Document("$toLower", "$senderEmail"))))
The following documentation on Update Many using Java might also be helpful in this case.
Please note that MongoDB Compass and Atlas provides with the feature to export the aggregation pipelines to language specific codes.
Please refer to the documentation for Export Pipeline to Specific Language in compass and Atlas for trying out.
Hi @Aasawari , can u tell me how I use the list of documents in mongoTemplate. I don’t see any method accepting List. Also the query that I have share I found it from internet, it is aggregation update query, right now I am not using that version. so is there any way to write java code with version 2.7.1 to set field value to lower case.
I’m not sure I understand the goal you’re trying to achieve. I think you are trying to convert some part of your document to lower case, and save the result back in the database. Is this correct? Could you post some document example and the result you’re trying to get?
Could you also help us in understanding if Java is a requirement for the application. If not, $merge would help.
Else, please help with the driver and MongoDB versions for the application.
Please refer to the below snippet for further understanding.
Hi @Aasawari , the example that you added is correct, we have documents where recipient/sender emails value are in upper case and we won’t to update them in lower case.