如何进行查询包括计数和集合数据
示例数据
[
{ owner: '0x123124124', createdAt: '13 May 2022 at 04:20:21 UTC'},
{ owner: '0x123124124', createdAt: '13 May 2022 at 06:20:21 UTC'},
{ owner: '0x123124124', createdAt: '13 May 2022 at 03:20:21 UTC'},
{ owner: '0x123124124', createdAt: '12 May 2022 at 07:39:34 UTC'},
{ owner: '0x123124124', createdAt: '12 May 2022 at 07:39:34 UTC'},
{ owner: '0x454545627', createdAt: '11 May 2022 at 04:13:48 UTC'}
]
和我想查询这样的返回数据,
[
{ owner: '0x123124124', createdAt: '13 May 2022', count: 3},
{ owner: '0x123124124', createdAt: '13 May 2022', count: 2},
{ owner: '0x454545627', createdAt: '11 May 2022', count: 1},
]
我已经将其舍入数小时了几个小时。 感谢您的帮助。
Example data
[
{ owner: '0x123124124', createdAt: '13 May 2022 at 04:20:21 UTC'},
{ owner: '0x123124124', createdAt: '13 May 2022 at 06:20:21 UTC'},
{ owner: '0x123124124', createdAt: '13 May 2022 at 03:20:21 UTC'},
{ owner: '0x123124124', createdAt: '12 May 2022 at 07:39:34 UTC'},
{ owner: '0x123124124', createdAt: '12 May 2022 at 07:39:34 UTC'},
{ owner: '0x454545627', createdAt: '11 May 2022 at 04:13:48 UTC'}
]
And I want to query return data like this
[
{ owner: '0x123124124', createdAt: '13 May 2022', count: 3},
{ owner: '0x123124124', createdAt: '13 May 2022', count: 2},
{ owner: '0x454545627', createdAt: '11 May 2022', count: 1},
]
I have rounded with this for hours.
Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$ set
- set创建
with1.1。
$ trim
- 1.1.1 。的修剪字符串
1.1.1。
$ arrayelemat
- 从 1.1.1.1 。获取第一个值
1.1.1.1。
$ split
- split 创建 word“ at”。的字符串
$ group
- 组成的组所有者
和创建
并执行计数。$ project
- 装饰输出文档。示例mongo playground
$set
- SetcreatedAt
with1.1.
$trim
- Trim string from 1.1.1.1.1.1.
$arrayElemAt
- Get the first value from 1.1.1.1.1.1.1.1.
$split
- SplitcreatedAt
string with word "at".$group
- Group byowner
andcreatedAt
and perform count.$project
- Decorate output documents.Sample Mongo Playground