Home > database >  Help: directing a MongoTemplate one attribute value, if the array elements are inserted the element.
Help: directing a MongoTemplate one attribute value, if the array elements are inserted the element.

Time:09-29

Directing the table UserRole,
Object:
UserRole {
String roleId,
List}
UserRoleCert {
String certHash,
String certName,
String certPath,
String createTime,
String txId
}
If the mongo's data is as follows:
/* */0
{
"_id" : ObjectId (" 5 a6adf9c14f66c207c8fde23 "),
"_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
"}]
}
Above is to prepare data,
Now need to decide as follows: if an element of an array of userRoleCert certHash contains hash_3 then no operation, if does not include the insert hash_3 userRoleCert object to the array,
Excuse me: how to use the spring MongoTemplate implementation?
Myself is a stupid way: 1, the query to get the data to the Java 2, through 3, compared to delete 4, new

CodePudding user response:

Go to the next push, pushall pull, pull the usage
  • Related