我对Mongo相当陌生,我有一个像这样的JSON对象:
{
"_id": 155,
"supplier_id": 978,
"supplier": "MK Couriers & Exports",
"is_active": 1,
"rates": [{
"zipcode": "35816",
"is_origin": "1",
"durations": "{\"ALASKA\":{\"d\":\"6\",\"p\":\"6\"},\"KENTUCKY\":{\"d\":\"7\",\"p\":\"7\"},\"GEORGIA\":{\"d\":\"6\",\"p\":\"6\"},\"KANSAS\":{\"d\":\"6\",\"p\":\"6\"},\"MINNESOTA\":{\"d\":\"6\",\"p\":\"6\"},\"OHIO\":{\"d\":\"7\",\"p\":\"7\"},\"OREGON\":{\"d\":\"6\",\"p\":\"6\"},\"TENNESSEE\":{\"d\":\"7\",\"p\":\"7\"},\"ROA\":{\"d\":\"8\",\"p\":\"8\"}}",
"has_cod": "1",
"has_express": "1",
"created_at": "2018-05-24 13:17:09",
"updated_at": "2018-05-24 13:17:09",
"has_cash": "0",
"has_repl": "0",
"city": "1",
"state": "2",
"region": "Z1"
},
{
"zipcode": "90089",
"is_origin": "1",
"durations": "{\"ALASKA\":{\"d\":\"6\",\"p\":\"6\"},\"KENTUCKY\":{\"d\":\"7\",\"p\":\"7\"},\"GEORGIA\":{\"d\":\"6\",\"p\":\"6\"},\"KANSAS\":{\"d\":\"6\",\"p\":\"6\"},\"MINNESOTA\":{\"d\":\"6\",\"p\":\"6\"},\"OHIO\":{\"d\":\"7\",\"p\":\"7\"},\"OREGON\":{\"d\":\"6\",\"p\":\"6\"},\"TENNESSEE\":{\"d\":\"7\",\"p\":\"7\"},\"ROA\":{\"d\":\"8\",\"p\":\"8\"}}",
"has_cod": "1",
"has_express": "1",
"created_at": "2018-05-24 13:17:09",
"updated_at": "2018-05-24 13:17:09",
"has_cash": "0",
"has_repl": "0",
"city": "2",
"state": "2",
"region": "Z3"
},
{
"zipcode": "67201",
"is_origin": "1",
"durations": "{\"ALASKA\":{\"d\":\"6\",\"p\":\"6\"},\"KENTUCKY\":{\"d\":\"7\",\"p\":\"7\"},\"GEORGIA\":{\"d\":\"6\",\"p\":\"6\"},\"KANSAS\":{\"d\":\"6\",\"p\":\"6\"},\"MINNESOTA\":{\"d\":\"6\",\"p\":\"6\"},\"OHIO\":{\"d\":\"7\",\"p\":\"7\"},\"OREGON\":{\"d\":\"6\",\"p\":\"6\"},\"TENNESSEE\":{\"d\":\"7\",\"p\":\"7\"},\"ROA\":{\"d\":\"8\",\"p\":\"8\"}}",
"has_cod": "1",
"has_express": "1",
"created_at": "2018-05-24 13:17:09",
"updated_at": "2018-05-24 13:17:09",
"has_cash": "0",
"has_repl": "0",
"city": "1",
"state": "2",
"region": "Z1"
}
],
"costing": [{
"costing_logic": ["0.5", "*0.5"],
"per_slab_cost": [{
"wc": "20",
"mm": "32",
"ROA": "37",
"0": {
"states": {
"qualifiers": ["Additional"],
"rate": "95"
}
}
}, {
"wc": "30",
"mm": "42",
"ROA": "47",
"0": {
"states": {
"qualifiers": ["ODA"],
"rate": "115"
}
}
}],
"service_tax": 0.1500,
"fuel_surcharge": 0.30,
"cod_tax": "1% or 30",
"created_at": "2017-11-21 11:15:41",
"updated_at": "2017-11-21 11:15:41",
"from_date": "2017-11-21 11:15:41",
"classes": {
"mm": [""]
},
"extra_charges": [],
"volumetric_formula": "l*b*h/6000",
"user_id": 0,
"is_reverse": 0
}]
}
现在,我有两个输入的邮政编码(例如:35816、67201)。
用例:
如果有人在搜索上面的个人识别码,则应首先检查原始个人识别码是否具有rates.is_origin = 1
预期的产量:返回满足特定邮政编码的所有供应商的列表。
截至目前的查询是:
$zipcodes = DB::connection('mongodb')->collection('air_domestic')
->where('is_active', '=', 1)
->where('rates.zipcode', 'elemMatch', [ 'zipcode' => "'" . $request['origin_zipcode'] . "'" ])
->where('rates.is_origin', '=', 1)
->orderBy('supplier_id', 'desc')
->take(10)
->get();
但是此查询不起作用。它返回0(零计数)。
有人可以在这方面帮助我吗?