是否可以使用SpringMongoTemplate进行更新,从而推送到已排序的数组?
有人知道如何使用是否可以使用SpringMongoTemplate进行更新,从而推送到已排序的数组?,spring,sorting,push,spring-data-mongodb,mongotemplate,Spring,Sorting,Push,Spring Data Mongodb,Mongotemplate,有人知道如何使用MongoTemplate.find和modify将元素推送到已排序的数组中吗 它看起来不像MongoTemplate支持update$sort操作符 使用$sort对$push$each的支持目前不可用于更新。有关此问题的进展,请参阅。同时,您可以使用BasicUpdate创建所需的语句 Update update = new BasicUpdate(new BasicDBObject()); update.push("yourFieldNameHere", new Basic
MongoTemplate.find和modify
将元素推送到已排序的数组中吗
它看起来不像MongoTemplate
支持update$sort
操作符
使用
$sort
对$push$each
的支持目前不可用于更新
。有关此问题的进展,请参阅。同时,您可以使用BasicUpdate
创建所需的语句
Update update = new BasicUpdate(new BasicDBObject());
update.push("yourFieldNameHere", new BasicDBObjectBuilder()
.add("$each", Arrays.asList("foo", "bar"))
.add("$sort", 1).get());
将创造
{
"$push": {
"yourFieldNameHere": {
"$each": ["foo","bar"],
"$sort": 1
}
}
}