'How to set a max length on collection index in mongodb
Using Pymongo to set/query/insert in my mongodb database.
It is possible to indicate that a value should be a unique index in mongodb.
db.mycoll.create_index("sid", unique=True) # This is what I have so far
Now, I want to make sure that the index has a minimum and maximum length. (3-20 chars).
I didn't find any information about adding length restrictions, is it possible with mongodb ?
I would expect something like this:
db.mycoll.create_index("sid", unique=True, max_len=20, min_len=3) # Is there a way to do this ?
If you need a bit more context, I have a collection in mongodb and for every document I need a SID (string ID). I would like to put a technical size limit on this value, so I can be sure on every side of my application that any string which doesn't match this size is not a proper id.
Thanks a lot
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
