0

嗨!我有这个 JSON 结构:

 {
    "author" : "some author"
    "comment" : [{
          "text" : "some text",
          "date" : "some date",
       }, {
           "text" : "some text",
          "date" : "some date",
       }]
}

例如,我需要检查所有评论日期。我写了这段代码:

    UpdateOperations<Blog> ops;
    Query<Blog> updateQuery = ds.createQuery(Blog.class).disableValidation().filter("comment.$.date", "some date").enableValidation();

    ops = ds.createUpdateOperations(Blog.class).disableValidation().set("comment.$.text", "new text").enableValidation();
ds.update(updateQuery, ops);

但它不起作用。你能告诉我如何处理吗啡中的对象数组吗?

4

1 回答 1

1

过滤器不应该有$您可以使用点符号的运算符。尝试:

UpdateOperations<Blog> ops;
Query<Blog> updateQuery = ds.createQuery(Blog.class).field("comment.date").equal("some date");
ops = ds.createUpdateOperations(Blog.class).disableValidation().set("comment.$.text", "new text").enableValidation();
于 2012-07-25T14:40:41.753 回答