multi location documents #400

Closed
bazo opened this Issue Aug 29, 2012 · 5 comments

Comments

Projects
None yet
3 participants
@bazo

bazo commented Aug 29, 2012

since 1.9 mongo supports multi location documents http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-MultilocationDocuments

how can i define such a document in mongo odm? is it supported? if not, will it be added?

@jmikola

This comment has been minimized.

Show comment Hide comment
@jmikola

jmikola Aug 29, 2012

Owner

Have you tried defining the usual geo index on the field containing an array of points? I expect this would function much like multi-key indexing, which doesn't require any special support on ODM's part.

Owner

jmikola commented Aug 29, 2012

Have you tried defining the usual geo index on the field containing an array of points? I expect this would function much like multi-key indexing, which doesn't require any special support on ODM's part.

@bazo

This comment has been minimized.

Show comment Hide comment
@bazo

bazo Aug 29, 2012

that work, thanks. but i realized it is useless, since array of points is just one field. what i need is to set a start and an end place to the object and query by both start and end.

like this

$qb->field('start')->withinCenter($coordinatesStart['lon'], $coordinatesStart['lat'], 60);
$qb->field('end')->withinCenter($coordinatesEnd['lon'], $coordinatesEnd['lat'], 50);

i dont think this is possible or is it?

bazo commented Aug 29, 2012

that work, thanks. but i realized it is useless, since array of points is just one field. what i need is to set a start and an end place to the object and query by both start and end.

like this

$qb->field('start')->withinCenter($coordinatesStart['lon'], $coordinatesStart['lat'], 60);
$qb->field('end')->withinCenter($coordinatesEnd['lon'], $coordinatesEnd['lat'], 50);

i dont think this is possible or is it?

@jmikola

This comment has been minimized.

Show comment Hide comment
@jmikola

jmikola Aug 30, 2012

Owner

That would require two geospatial indexes in the collection (on start and end, respectively), which is not supported in Mongo. From the documentation page:

You may only have 1 geospatial index per collection, for now. While MongoDB may allow to create multiple indexes, this behavior is unsupported. Because MongoDB can only use one index to support a single query, in most cases, having multiple geo indexes will produce undesirable behavior.

You may be able to get by with something like the following:

{
    _id: ObjectId("..."),
    start_end: [
        [0,0], [2,2]
    ],
    other: "fields"
}

And then querying on start_end.0 and start_end.1, using a multi-location index on start_end. I would suggest storing your points as simple arrays (i.e. [x, y]) instead of embedded objects. The documentation page also explains why that's preferable.

Owner

jmikola commented Aug 30, 2012

That would require two geospatial indexes in the collection (on start and end, respectively), which is not supported in Mongo. From the documentation page:

You may only have 1 geospatial index per collection, for now. While MongoDB may allow to create multiple indexes, this behavior is unsupported. Because MongoDB can only use one index to support a single query, in most cases, having multiple geo indexes will produce undesirable behavior.

You may be able to get by with something like the following:

{
    _id: ObjectId("..."),
    start_end: [
        [0,0], [2,2]
    ],
    other: "fields"
}

And then querying on start_end.0 and start_end.1, using a multi-location index on start_end. I would suggest storing your points as simple arrays (i.e. [x, y]) instead of embedded objects. The documentation page also explains why that's preferable.

@bazo

This comment has been minimized.

Show comment Hide comment
@bazo

bazo Aug 30, 2012

so i tried something like this:

/**
 * @ODM\Document
 * @ODM\Index(keys={"points"="2d"})
 */
class Listing
{
    protected 
        /** 
         * @ODM\Id 
         */ 
        $id,

        /**
         * @ODM\Collection
         */ 
        $points = array()
    ;
}   

and the query

$qb->field('points.0')->withinCenter($coordinates['lon'], $coordinates['lat'], 60);

but i get an error

can't find special index: 2d for: { points.0: { $within: { $center: [ [ 17.106983, 48.155551 ], 60 ] } } }

but this works:

$qb->field('points')->withinCenter($coordinates['lon'], $coordinates['lat'], 60);

it gives me some results, but i'm not sure how to interpret them

bazo commented Aug 30, 2012

so i tried something like this:

/**
 * @ODM\Document
 * @ODM\Index(keys={"points"="2d"})
 */
class Listing
{
    protected 
        /** 
         * @ODM\Id 
         */ 
        $id,

        /**
         * @ODM\Collection
         */ 
        $points = array()
    ;
}   

and the query

$qb->field('points.0')->withinCenter($coordinates['lon'], $coordinates['lat'], 60);

but i get an error

can't find special index: 2d for: { points.0: { $within: { $center: [ [ 17.106983, 48.155551 ], 60 ] } } }

but this works:

$qb->field('points')->withinCenter($coordinates['lon'], $coordinates['lat'], 60);

it gives me some results, but i'm not sure how to interpret them

@malarzm malarzm added the question label Jan 16, 2016

@malarzm

This comment has been minimized.

Show comment Hide comment
@malarzm

malarzm Jun 21, 2017

Member

Closing since a lot of time has passed, if problem is still relevant and ODM is the culprit, please reopen.

Member

malarzm commented Jun 21, 2017

Closing since a lot of time has passed, if problem is still relevant and ODM is the culprit, please reopen.

@malarzm malarzm closed this Jun 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment