样品收集:
{
model: Pants,
colors: [green, blue]
},
{
model: Trousers,
colors: [red, blue, yellow]
},
...
我想使用mongodb聚合框架将字段colors
的所有数组随机化。
可能的解决方案:
{
model: Pants,
colors: [blue, green]
},
{
model: Trousers,
colors: [yellow, red, blue]
},
...
我发现了$sample pipeline stage,但这似乎仅适用于查询本身,不适用于其文档的数组值。
有没有办法用mongodb做到这一点?
我正在使用Mongo 3.6 。
感谢您的帮助!