简体   繁体   English

Doctrine MongoDB - 有没有办法从JSON构建查询?

[英]Doctrine MongoDB - is there any way to build a query from JSON?

I have an arbitrary MongoDB JSON find query string, for example: 我有一个任意MongoDB JSON查找查询字符串,例如:

{ "address.city": "Seattle"}

or 要么

{ qty: { $gt: 5, $lt: 50 }

Is there any existing method to create a Doctrine.MongoDB.Query object from the JSON string? 是否有任何现有方法从JSON字符串创建Doctrine.MongoDB.Query对象? Or alternately to query mongo directly and then pass those results to doctrine for hydration? 或者直接查询mongo然后将这些结果传递给学说进行补水?

Is there any existing method to create a Doctrine.MongoDB.Query object from the JSON string? 是否有任何现有方法从JSON字符串创建Doctrine.MongoDB.Query对象?

At this moment no, however we could add setQuery method to the Builder . 此刻没有,但是我们可以在Builder添加setQuery方法。 More tedious, but working, would be instantiating Query class on your own. 更乏味但有效,将自己实例化Query类。

Or alternately to query mongo directly and then pass those results to doctrine for hydration? 或者直接查询mongo然后将这些结果传递给学说进行补水?

Once you have plain arrays with data (and you're not afraid to dive into UnitOfWork ) you may utilize $dm->getUnitOfWork()->getOrCreateDocument() or employ HydratorFactory and merge documents into DocumentManager later. 一旦你有了数据的普通数组(并且你不害怕潜入UnitOfWork ),你可以使用$ dm-> getUnitOfWork() - > getOrCreateDocument()或使用HydratorFactory并稍后将文档合并到DocumentManager

I haven't used it myself, but this recent bundle appears to have been created to serve this exact purpose (querybuilderjs into doctrine). 我自己没有使用它,但是这个最近的捆绑似乎是为了达到这个目的而创建的(querybuilderjs into doctrine)。

https://github.com/fourlabsldn/QBJSParserBundle https://github.com/fourlabsldn/QBJSParserBundle

https://github.com/fourlabsldn/QBJSParser https://github.com/fourlabsldn/QBJSParser

         $parsedRuleGroup = $this->get('fl_qbjs_parser.json_query_parser.doctrine_orm_parser')->parseJsonString($jsonString, Product::class);

         $query = $this->get('doctrine.orm.entity_manager')->createQuery($parsedRuleGroup->getDqlString());
         $query->setParameters($parsedRuleGroup->getParameters());
         $results = $query->execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM