Code Monkey home page Code Monkey logo

Comments (15)

fiorix avatar fiorix commented on July 4, 2024

Have you seen this example: https://github.com/fiorix/mongo-async-python-driver/blob/master/examples/index.py

from txmongo.

zman0900 avatar zman0900 commented on July 4, 2024

This is causing problems for me as well. I have seen the example, but geospatial indices need to be set up in a different way. They have to be specified like:
db.places.ensureIndex( { loc : "2d" } )
or, if you are not using the normal coordinate range, like:
db.places.ensureIndex( { loc : "2d" } , { min : -500 , max : 500 } )

I have spent some time studying the code, but I don't see an easy way to go about doing that without changing the code to txmongo. Check out this page for more info: http://www.mongodb.org/display/DOCS/Geospatial+Indexing

from txmongo.

kientzlecatch avatar kientzlecatch commented on July 4, 2024

Here's a standalone _create_index() that should do what you need. It accepts sort lists (like pymongo) in addition to filter.sort objects and passes through additional kwargs, which should allow it to be used to create geo indexes, as well as support background=True and other modifiers. Not yet extensively tested.

from   bson.son               import SON
from   pymongo                import helpers
from   txmongo                import filter

"""Usage: _create_index(db.coll, [('key1', ASCENDING)], background=True) """

def _create_index(collection, sort_fields, unique=False, dropDups=False, **kwargs):
    def wrapper(result, name):
        return name

    if isinstance(sort_fields, filter.sort):
        keys = list(sort_fields["orderby"])
    else:
        keys = helpers._index_list(sort_fields)

    name = u"_".join([u"%s_%s" % item for item in keys])
    index = dict(
        ns=str(collection),
        name=name,
        key=helpers._index_document(keys))
        unique=unique,
        dropDups=dropDups,
    )
    index.update(kwargs)

    d = collection._database.system.indexes.insert(SON(index), safe=True)
    d.addCallback(wrapper, name)
    return d

from txmongo.

doncatnip avatar doncatnip commented on July 4, 2024

Thx kientzlecatch, works quite well after fixing imports and syntax :)

But it's still a dirty workaround, depending on pymongo. So, I'd like to see a proper ensure_index implemented. Especially since geospacial indexing is a damn cool feature of the mongo.

from txmongo.

fiorix avatar fiorix commented on July 4, 2024

I wish I could do it but I'm quite busy with other stuff. So, I'll kindly wait for a pull request.

from txmongo.

dynamicgl avatar dynamicgl commented on July 4, 2024

Hi..I want to know GEO2D index has been available or not?

Thanks

from txmongo.

fiorix avatar fiorix commented on July 4, 2024

No. I haven't had the time to work on it.

from txmongo.

rnz0 avatar rnz0 commented on July 4, 2024

It seems that not only GEO2D indices need implementation but also the new GEOHAYSTACK (http://www.mongodb.org/display/DOCS/Geospatial+Haystack+Indexing). Use of unique and dropUps as parameters has been deprecated in pymongo. Geo adds more parameters, namely min, max and bucketSize, so the list may keep growing and makes sense to move all to **kwargs. I can propose a fix.

from txmongo.

gleicon avatar gleicon commented on July 4, 2024

@rnz0 supplied a pull request that I'm willing to merge. But as I dont really have a grasp on geo stuff using mongodb, I'd like to everyone in this ticket help testing so I can have material to write the docs (and learn more about the ins and outs). Please let me know who is testing so I can merge the pull request today if possible. Thanks

from txmongo.

psi29a avatar psi29a commented on July 4, 2024

@kientzlecatch Would be so kind as to make a pull request? :)

from txmongo.

psi29a avatar psi29a commented on July 4, 2024

@rnz0 Do you still have that pull request?

@gleicon I can also review and test this if the PR is there.

from txmongo.

gleicon avatar gleicon commented on July 4, 2024

thanks @psi29a I don't see the PR anymore. In any case if you want to work on it let me know how I can help.

from txmongo.

psi29a avatar psi29a commented on July 4, 2024

This looks to be partially enabled, we have GEO2D support but the ensure_index is just a wrapper around create_index.

As of pymongo 3.0, ensure_index is deprecated. So as far as I'm concerned, this can be closed.
http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.ensure_index

Any objections or comments?

from txmongo.

gleicon avatar gleicon commented on July 4, 2024

Ok for me. I've proceeded with some tests at the time this was opened but didn't had the full grasp of GEO + mongo to submit something meaningful. Ping me if you need any help. Thanks.

from txmongo.

fiorix avatar fiorix commented on July 4, 2024

+1

from txmongo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.