3

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.

4

2 回答 2

12

pymongo 的示例:

import pymongo

mongo = pymongo.Connection('localhost')
collection = mongo['database']['hosts']
collection.ensure_index('host_name', unique=True)
于 2011-06-26T09:16:34.443 回答
8

感谢#mongodb中的skot

一种解决方案是:

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

用于在操作列表中的时间字段上创建索引。

于 2010-07-24T15:13:49.937 回答