【发布时间】:2016-01-29 07:08:26
【问题描述】:
我的文件如下:
{
"_id" : ObjectId("53b246aae4b0ad1d6b6a5c02"),
"name" : "PATHOLOGY",
"status" : true,
"history" : [
{
"updateBy" : "53bcc05a48d1665cd8692993",
"date" : ISODate("2014-12-20T10:19:07.246Z")
}
]
}
我想在history key 中保留最近 5 个历史记录:
所以我可以为此编写以下查询:
db.collection.update(
{ "_id" : ObjectId("53b246aae4b0ad1d6b6a5c02") },
{ $push : {
history :
{
$each : [
{
"updateBy" : "53bcc05a48d1665cd8692993",
"date" : new Date()
}
] ,
$slice : -5
}
}
}
);
但我不知道如何用$slice、$each 和$push 在MongoTemplate 中编写update 查询。
【问题讨论】:
-
$slice尚不支持 spring-data-mongodb 中的Update。请为DATAMONGO-832投票。
标签: java mongodb spring-data mongotemplate