現(xiàn)在條件是一個(gè)List,如 type["sh","th"] //不是數(shù)據(jù)庫(kù)type里面的全值,只有一個(gè)前綴
根據(jù)這個(gè)查詢(xún)下面數(shù)據(jù)庫(kù),type里面有sh和th為前綴的,整個(gè)document
結(jié)果應(yīng)該是1,2,4條record(document)都應(yīng)該被查出來(lái)
怎么實(shí)現(xiàn),最好用springdata mongdb,其它java方式也行
比如數(shù)據(jù)庫(kù)有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貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊
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);?
添加回答
舉報(bào)
0/150
提交
取消