各种查询 - MongoDB
这是我的表格:
unicorns = {'name':'George',
'actions':[{'action':'jump', 'time':123123},
{'action':'run', 'time':345345},
...]}
如何执行以下查询?
抓取所有独角兽的所有操作的时间,其中<strong> action=='jump' ?
在时间相等的情况下抓取所有独角兽的所有行动?
例如 {'action':'jump', 'time':123} 和 {'action':'stomp', 'time':123}
帮助会很棒 =)
This is my table:
unicorns = {'name':'George',
'actions':[{'action':'jump', 'time':123123},
{'action':'run', 'time':345345},
...]}
How can I perform the following queries?
Grab the time of all actions of all unicorns where action=='jump' ?
Grab all actions of all unicorns where time is equal?
e.g. {'action':'jump', 'time':123} and {'action':'stomp', 'time':123}
Help would be amazing =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于第二个查询,您需要使用MapReduce,这可能会带来很大的麻烦。这会起作用:
这将返回类似这样的内容,其中
_id
键是您的时间戳:不幸的是,mongo当前不支持从reduce函数返回数组,因此需要愚蠢的
{ actions: [...]}
语法。For the second query, you need to use MapReduce, which can get a big hairy. This will work:
This would return something like this, where the
_id
keys are your timestamps:Unfortunately, mongo doesn't currently support returning an array from a reduce function, thus necessitating the silly
{actions: [...]}
syntax.使用点分隔符号:
时间类似:
编辑:如果要按时间对结果进行分组,则必须使用 MapReduce。
Use dot-separated notation:
Similarly for times:
Edit: if you want to group the results by time, you'll have to use MapReduce.