Gabriel Gabriel - 15 days ago 8
Java Question

Insert $currentDate in java.util.List using Spring-data

I need to make an update and use the mongo operator $currentDate in a document I am using spring-data-mongodb the problem is, I can't traverse the element
Example:

Update update = new Update();
update.set("list", listOfObjects);
update.currentDate("list.someDate");


Error:

Write failed with error code 16837 and error message 'cannot use the part (list of list.someDate) to traverse the element(...)


Someone know a solution or some workaround?
Obs. The date must be the MongoDb date, I can't use the Java date, I can't use this:

update.set("lista.dataAlteracao", DateTime.now())

Answer

Your error is not related to date.

its more of your query/code is not able to identify how to access someDate which you are saying is sitting inside list. read a bit about positional operator and in such cases it is a savior.

you probably need to change your code a bit to include something like list.$.someDate.

can you post how your document looks like so that i can give you a better answer.