Question

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.

Was it helpful?

Solution 2

Thanks to skot in #mongodb!!

One solution is:

[...].ensureIndex({"actions.time":1})

for creating an index on the time field within the actions list.

OTHER TIPS

Example for pymongo:

import pymongo

mongo = pymongo.Connection('localhost')
collection = mongo['database']['hosts']
collection.ensure_index('host_name', unique=True)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top