MongoDB - 查询数组的最后一个元素? [英] MongoDB - Query on the last element of an array?

查看:91
本文介绍了MongoDB - 查询数组的最后一个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 MongoDB 支持语法 find{array.0.field:"value"},但我特别想对数组中的最后一个元素执行此操作,这意味着我不不知道索引.是否有某种运营商可以解决这个问题,还是我运气不好?

I know that MongoDB supports the syntax find{array.0.field:"value"}, but I specifically want to do this for the last element in the array, which means I don't know the index. Is there some kind of operator for this, or am I out of luck?

澄清一下,我希望 find() 仅返回数组最后一个元素中的字段与特定值匹配的文档.

To clarify, I want find() to only return documents where a field in the last element of an array matches a specific value.

推荐答案

我在官方的 Mongo Google 群组中发帖 这里,并从他们的工作人员那里得到了答复.看来我要找的东西是不可能的.我将使用不同的模式方法.

I posted on the official Mongo Google group here, and got an answer from their staff. It appears that what I'm looking for isn't possible. I'm going to just use a different schema approach.

这篇关于MongoDB - 查询数组的最后一个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆