mongodb中的表是UserRole 。
物件:
UserRole {
String roleId,
List<UserRoleCert >
}
UserRoleCert {
String certHash,
String certName,
String certPath,
String createTime,
String txId
}
假如mongodb的資料如下:
/* 0 */
{
"_id" : ObjectId("5a6adf9c14f66c207c8fde23"),
"_class" : "com.abs.pojo.MongoUserRole",
"roleId" : "role_id_1",
"userRoleCert" : [{
"certHash" : "hash_0",
"certName" : "name_0",
"certPath" : "path_0",
"createTime" : "createTime_0",
"txId" : "txId_0"
}, {
"certHash" : "hash_2",
"certName" : "name_2",
"certPath" : "path_2",
"createTime" : "createTime_2",
"txId" : "txId_2"
}]
}
以上是準備資料。
現在需要判斷如下:如果userRoleCert陣列的某個元素的certHash 包含hash_3 那么就不操作,如果不包含則插入hash_3所在的UserRoleCert物件到該陣列。
請問:該如何用spring MongoTemplate 實作?
我自己已實作一個笨辦法:1、查詢拿到資料到java 2、遍歷 3、比較洗掉 4、新增
uj5u.com熱心網友回復:
去看下push ,pushall pull,pull的用法轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/98158.html
標籤:MongoDB
