現在條件是一個List,如 type["sh","th"] //不是數據庫type里面的全值,只有一個前綴
根據這個查詢下面數據庫,type里面有sh和th為前綴的,整個document
結果應該是1,2,4條record(document)都應該被查出來
怎么實現,最好用springdata mongdb,其它java方式也行
比如數據庫有3條record如下:
{
"_id": "5bcfe3367f0xxxxx02",
"type": [
"sh-adidas",
"th-NB"
],
"status": "active",
"lastUpdateDate": "2018-10-25T17:27:41+08:00"
}
{
"_id": "5bcfe3367f0xxxxx02",
"type": [
"bj-nike",
"sh-adidas"
],
"status": "active",
"lastUpdateDate": "2018-10-25T17:27:41+08:00"
}
{
"_id": "5bcfe3367f0xxxxx02",
"type": [
"bj-nike"
],
"status": "active",
"lastUpdateDate": "2018-10-25T17:27:41+08:00"
}
{
"_id": "5bcfe3367f0xxxxx02",
"type": [
"bj-nike",
"sh-adidas",
"th-NB",
"th-vans"
],
"status": "active",
"lastUpdateDate": "2018-10-25T17:27:41+08:00"
}
1 回答

慕后森
TA貢獻1802條經驗 獲得超5個贊
mongoSQL:
db.inventory.find({"$or":[{type:{"$regex":"sh"}},{type:{"$regex":"bj"}}]});
SpringData Mongo:
Query qury = query.orOperator(Criteria.where("type").regex("sh"),Criteria.where("type").regex("bj"));
mongoTemplate.find(qury,entityClass);?
添加回答
舉報
0/150
提交
取消