如何在mongodb中进行嵌套搜索?

时间:2015-12-23 13:11:48

标签: php mongodb

我是mongodb的新手。在门户网站上工作我想实现一个嵌套的搜索。我的数据如下:

$query = $mongoDb->find(array('City' => $city,  'SubjectValuation.Subject' => $subject, 'SubjectValuation.Primary' => $level));

我跑的查询是:

$subject

当我通过数学'在public object BindModel(ControllerContext controllerContext, System.Web.Mvc.ModelBindingContext bindingContext) { string type = controllerContext.HttpContext.Request.Form["ModelName"]; if (type == null) { throw new MissingFieldException("ModelName wasn't found"); } type = type.Substring(type.LastIndexOf('.') + 1); HttpRequestBase request = controllerContext.HttpContext.Request; switch (type) { case "MissingDeliveryNoteNumberModel": MissingDeliveryNoteNumberModel mdnnModel = new MissingDeliveryNoteNumberModel(request); return mdnnModel; case "MissingCardBoxModel": MissingCardBoxModel mcbModel = new MissingCardBoxModel(request); return mcbModel; case "WrongItemsReceivedModel": WrongItemsReceivedModel wirModel = new WrongItemsReceivedModel(request); return wirModel; default: return null; } } 我得到了一个结果,但是当我通过英语'然后没有记录被检索。如何为这种数组实现嵌套搜索?

1 个答案:

答案 0 :(得分:0)

试试这个没有经过测试但在逻辑上它可以工作 $ query = $ mongoDb-> find(array('City'=> $ city,'$ and'=> ['SubjectValuation.Subject'=> $ subject,'SubjectValuation.Primary'=> $ level ]));