本文介绍了mongotemplate聚合具有独特的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用mongotemplate,我的收藏如下:
I am using mongotemplate , my collection look like this:
{
"_id": "theid",
"tag": "taga",
"somefield": "some value",
"fieldC": {
"anotherfielad": "more data",
"an_array": [
{
"a": "abc",
"b": 5
},
{
"a": "bca",
"b": 44
},
{
"a": "ddd",
"b": 21
}
]
}
}
{
"_id": "anotherid",
"tag": "taga",
"somefield": "some other value",
"fieldC": {
"anotherfielad": "other more data",
"an_array": [
{
"a": "ccc",
"b": 6
},
{
"a": "abc",
"b": 99
},
{
"a": "ddd",
"b": 21
}
]
}
}
我需要从$ fieldC.an_array.a获得一个唯一的结果在这种情况下:("abc","bca","ddd","ccc")
I need to get a unique result from $fieldC.an_array.ain this case: ("abc","bca","ddd","ccc")
此查询有效:
[
{
"$match": {
"tag": "taga"
}
},
{
"$unwind": "fieldC.an_array"
},
{
"$group": {
"_id": null,
"array": {
"$addToSet": "fieldC.an_array.a"
}
}
}
]
但是我如何使用mongotemplate呢?
but how do I do it using mongotemplate ?
推荐答案
这就是您想要的 AggregrationTests .
这篇关于mongotemplate聚合具有独特的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!