How to use updateOption with arrayFilters in spring-data mongodb?

后端 未结 2 2032
误落风尘
误落风尘 2021-01-03 01:35

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

2条回答
  •  感情败类
    2021-01-03 01:57

    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 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))}
            )));
    

提交回复
热议问题