Home > database >  Mongo here how to query in the data structure, implementation is in Java
Mongo here how to query in the data structure, implementation is in Java

Time:09-29

in the Java operation,
Condition: all keyID=111111111111 and point=A record
The point here is in the inside of the remark, and display only point=A and the corresponding city, other B and C are not


{
"TempList" : [
{
"_id" : ObjectId (" 5 a6afcfce9ec67213fca393d8 "),
"KeyID" : "111111111111",
"Price" : 123,
"Remark" : [
{
"City", "Beijing",
"Point" : "A"
},
{
"City", "Shanghai",
"Point" : "A"
},
{
"City" : "through,"
"Point", "C"
}
]
},
{
"_id" : ObjectId (" 5 a6afcfce2121fca393d8 "),
"KeyID" : "111111111111",
"Price" : 456,
"Remark" : [
{
"City", "Beijing",
"Point" : "A"
},
{
"City", "Shanghai",
"Point" : "B"
},
{
"City" : "through,"
"Point", "C"
}
]
},
{
"_id" : ObjectId (" 5 a6afcfce9e32577223d8 "),
"KeyID" : "222222222222",
"Price" : 789,
"Remark" : [
{
"City", "Beijing",
"Point" : "A"
},
{
"City", "Shanghai",
"Point" : "B"
},
{
"City" : "through,"
"Point", "C"
}
]
}
]
}

===============================query result should look like this=================================
{
"TempList" : [
{
"_id" : ObjectId (" 5 a6afcfce9ec67213fca393d8 "),
"KeyID" : "111111111111",
"Price" : 123,
"Remark" : [
{
"City", "Beijing",
"Point" : "A"
},
{
"City", "Shanghai",
"Point" : "A"
}
]
},
{
"_id" : ObjectId (" 5 a6afcfce2121fca393d8 "),
"KeyID" : "111111111111",
"Price" : 456,
"Remark" : [
{
"City", "Beijing",
"Point" : "A"
}
]
}
]
}

CodePudding user response:

All selected first, in the condition of choice, eg.
The foreach ($data as $key=& gt; {$value)
The foreach ($value [' remark '] as $k=& gt; {$v)
If ($v [' point ']! {
='A')
The unset ($data [$key] [' remark '] [$k]);
}
}
}
  • Related