Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have an arbitrary MongoDB JSON find query string, for example:

{ "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? Or alternately to query mongo directly and then pass those results to doctrine for hydration?

like image 346
tgreiser Avatar asked Feb 02 '16 23:02

tgreiser


1 Answers

Is there any existing method to create a Doctrine.MongoDB.Query object from the JSON string?

At this moment no, however we could add setQuery method to the Builder. More tedious, but working, would be instantiating Query class on your own.

Or alternately to query mongo directly and then pass those results to doctrine for hydration?

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.

like image 157
malarzm Avatar answered Sep 28 '22 09:09

malarzm