Comments (15)
Have you seen this example: https://github.com/fiorix/mongo-async-python-driver/blob/master/examples/index.py
from txmongo.
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.
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.
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.
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.
Hi..I want to know GEO2D index has been available or not?
Thanks
from txmongo.
No. I haven't had the time to work on it.
from txmongo.
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.
@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.
@kientzlecatch Would be so kind as to make a pull request? :)
from txmongo.
@rnz0 Do you still have that pull request?
@gleicon I can also review and test this if the PR is there.
from txmongo.
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.
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.
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.
+1
from txmongo.
Related Issues (20)
- In disconnect: RuntimeError: dictionary changed size during iteration HOT 2
- When txmongo fails to connect mongodb, there is a memory leak HOT 8
- latest txmongo does not work with pymongo 3.7 HOT 3
- do not connect to mongodb+srv:// scheme HOT 1
- Does txmongo support compressors option? HOT 1
- builtins.AttributeError: '_CaseInsensitiveDictionary' object has no attribute 'copy' HOT 3
- Crash create_index: pymongo.errors.OperationFailure: cannot write to 'remains.system.indexes' HOT 2
- AssertionError: Tried to stop a LoopingCall that was not running. HOT 3
- txmongo not working with azure cosmos db HOT 19
- There should be a limit on the number of retries HOT 1
- insert_many does not work properly HOT 6
- maxIdleTimeMS support HOT 4
- does txmongo support transaction? HOT 2
- Proposing a PR to fix a few small typos HOT 1
- insert_many: unexpected keyword argument 'bypass_document_validation' in calling pymongo `_Bulk` HOT 2
- Import error with PyMongo==4.1.1. HOT 3
- Incompatible with mongodb >= 5.1 due to usage of deprecated `OP_QUERY` commands HOT 2
- txmongo with DocumentDB
- Incompatible with any version of DocumentDB HOT 3
- pymongo.errors.OperationFailure: TxMongo: not authorized for query on foo.test HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from txmongo.