我正在嘗試學習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