Extract distinct Fields values from mongoDB collection -


i'm quite new mongodb , i'm stuck simple (or not) problem:

i have collection of tagged products this:

{ "_id": "1", "tags": { "shape" : [ "shape1","shape2" ], "color": [ "col1","col2" ] }, { "_id": "2", "tags": { "shape" : [ "shape3","shape4" ], "color": [ "col3","col4" ] }, { "_id": "3", "tags": { "othercategory" : [ "value1" ], "color": [ "col5","col6" ] } 

i want select distinct category collection , have results:

[ "shape", "othercategory" ] 

how can achieve ? seems option find tags , parse manualy in java client...seems bad ;-)

i query mongodb java spring client.

thanks help.

ok ended refactoring model: looks it's not easy make queries on documents contents without doing map/reduce konstantin said.

to solve problem created new collection of categories can select them. collection populated when products insert.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -