I have a document as shown below in Mongodb:
Now, I want to go to a document based on specific \"_id
\" and for that document, want to go to \"schedu
It will soon be available in spring-data-mongodb. See : https://github.com/spring-projects/spring-data-mongodb/pull/656
Using it will look like :
new Update()
.set("grades.$[element]", 100)
.filterArray(Criteria.where("element").gte(100));
In the meantime, you should be able to use it with their snapshot maven repository:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.2.0.DATAMONGO-2215-SNAPSHOT</version>
</dependency>
<repository>
<id>spring-libs-snapshot</id>
<name>Spring Snapshot Repository</name>
<url>https://repo.spring.io/libs-snapshot</url>
</repository>
If there is no "updateOption" in spring-data, then we can use plain driver jar. I hope it will solve your problem.
MongoDatabase db = client.getDatabase("test");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z');
format.setTimeZone("EST");
List<Date> dateList = Arrays.asList(new Date[]
{format.parse("2018-07-10T00:30:00.000Z")}
);
db.getCollection("test").updateMany(new Document("_id", "x1"),
new Documen("$set", new Document("schedule.$[elem].status", "booked")),
new UpdateOptions().arrayFilters(Arrays.asList(new Document[]
{new Document("elem.Date", new Document("$in", dateList))}
)));