mongodb投影 - 从数组中获取第一个元素
我的字段“ field1.field2”是一个数组,我只想获取此数组的第一个元素,即“ field1.field2.0”,我想以其他任何给定的字段为例:“ field1.field2.0 .field3“。不幸的是,当我在Pymongo中使用此投影时,它不起作用(这个“ 0”会出现问题)。投影不会丢弃错误,但是“ 0”字段在投影之前包含值后的投影后不包含任何值。原因是什么?
My field "Field1.Field2" is an array and I want to take only first element of this array, i.e. "Field1.Field2.0" and from this I want to take any other given field for example: "Field1.Field2.0.Field3". Unfortunately when I use this projection in PyMongo then it doesn't work (this "0" make problems). The projection doesn't throw an error but the field "0" doesnt contain any values after projection while it contain the values before projection. What may be the reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
选项1:聚合/$ arrayat或$ first
playground 1
选项2:聚合/$ slice
Playground 2
/$ slice
Playground 3
Option 1:aggregation/$arrayAt or $first
Playground 1
Option 2:aggregation/$slice
Playground 2
Option 3:find/project/$slice
Playground 3