我正在尝试学习MongoDB以及它对于我来说如何对分析有用。我只是玩弄JavaScript控制台可以在他们的网站,并创造了以下项目:跨索引获取数组字段的独特聚合
{"title": "Cool", "_id": {"$oid": "503e4dc0cc93742e0d0ccad3"}, "tags": ["twenty", "sixty"]}
{"title": "Other", "_id": {"$oid": "503e4e5bcc93742e0d0ccad4"}, "tags": ["ten", "thirty"]}
{"title": "Ouch", "_id": {"$oid": "503e4e72cc93742e0d0ccad5"}, "tags": ["twenty", "seventy"]}
{"title": "Final", "_id": {"$oid": "503e4e72cc93742e0d0ccad6"}, "tags": ["sixty", "seventy"]}
我希望做的是查询,所以我得到的独特标签的列表中的所有这些对象。结果应该是这样的:
["ten", "twenty", "thirty", "sixty", "seventy"]
我该如何查询?我试图distinct()
它,但电话总是失败,甚至没有查询。
你得到什么错误讯息?我相信控制台运行在一个非常古老的mongo版本上... – Sammaye
这段代码与Mongo 3.6.0完美搭配使用 – kopos