Note that there are some explanatory texts on larger screens.

plurals
  1. POGeo spatial queries with Doctrine MongoDB ODM
    primarykey
    data
    text
    <p>I have a 2d index on a coordinates property of my document. Using the mongo shell, I can query the collection like this;</p> <pre><code>db.adverts.find({coordinates:{$near:[20,40]}}) </code></pre> <p>And that returns the following results, as expected;</p> <pre><code>{ "_id" : ObjectId("4fddac51352de93903000000"), "title" : "dummy #3", "coordinates" : { "longitude" : 22, "latitude" : 31 } } { "_id" : ObjectId("4fddac48352de95105000000"), "title" : "dummy #3", "coordinates" : { "longitude" : 20, "latitude" : 30 } } { "_id" : ObjectId("4fddaca4352de93703000000"), "title" : "dummy #3", "coordinates" : { "longitude" : 31, "latitude" : 22 } } { "_id" : ObjectId("4fdda6a2352de90a03000000"), "title" : "dummy title", "created" : ISODate("2012-06-17T09:42:58Z"), "coordinates" : { "longitude" : 54.1234, "latitude" : -1.234 } } { "_id" : ObjectId("4fdda6d8352de9c004000000"), "title" : "dummy title #2", "created" : ISODate("2012-06-17T09:43:52Z"), "coordinates" : { "longitude" : 54.34, "latitude" : -1.124 } } </code></pre> <p>However, using Doctrine as per the documentation to query the exact same collection, I get no results e.g.</p> <pre><code>$adverts = $dm-&gt;createQueryBuilder('Advert') -&gt;field('coordinates')-&gt;near(20, 40) -&gt;getQuery() -&gt;execute(); $adverts-&gt;count(); // =&gt; 0 </code></pre> <p>My advert yaml looks like this;</p> <pre><code>Advert: type: document collection: adverts fields: id: id: true title: type: string content: type: string created: type: date updated: type: date status: type: int distance: type: int indexes: coordinates: keys: coordinates: 2d referenceOne: owner: targetDocument: User embedOne: coordinates: targetDocument: Coordinates </code></pre> <p>And the Coordinates document is like this;</p> <pre><code>Coordinates: type: embeddedDocument fields: longitude: type: float latitude: type: float </code></pre> <p>Any ideas why using Doctrine's ODM would return zero results on the same query?</p> <p>UPDATE #1 It looks that there is a problem with Doctrine\MongoDB\Query\Builder::near() L363. The method parameter ignores the second value ($y). So only the first value is being passed to be executed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload