Reputation: 25557
My "table" looks like this:
{'name':'Rupert', 'type':'Unicorn', 'actions':[
{'time':0, 'position':[0,0], 'action':'run'},
{'time':50, 'position':[50,0], 'action':'stoprun'},
{'time':50, 'position':[50,0], 'action':'jump'},
{'time':55, 'position':[50,0], 'action':'laugh'},
...
]}
Is there any way I can index the items within the actions list? Or do I have to split them up into further tables?
It would be a lot more convenient for me to keep the actions within the current table row.
Upvotes: 3
Views: 7495
Reputation: 2366
Example for pymongo:
import pymongo
mongo = pymongo.Connection('localhost')
collection = mongo['database']['hosts']
collection.ensure_index('host_name', unique=True)
Upvotes: 12
Reputation: 25557
Thanks to skot in #mongodb!!
One solution is:
[...].ensureIndex({"actions.time":1})
for creating an index on the time field within the actions list.
Upvotes: 8