views:

17

answers:

1

I have an array of key values

{val1: [{gender:male}, {age:23}, {favorite-color:red}] }

The thing about this array is that in no way is it structured and in no way am I ever guaranteed to see the same key value again. For example I could see the following for val2

{val2: [{sex:male}, {hair-color:red}, {height:6'1"}] }

My question is whether is is better to have each of these keys as a column in mongo, or should I keep them in an array? I know with mongodb it is possible to create an arbitrarily large number of columns so either way would theoretically work. If I wanted to query if an array contained the key of 'sex' with a value of 'male', would that be possible in the example where I keep the values in a nested array in the object?

A: 

What's valX for anyways? I would just use regular "columns."

john : { gender:"male", age:23, favorite-color:red }
bob : { gender:"male", age:25, favorite-color:blue }
susan : { gender:"female", age:20, favorite-color:yellow }

You can search for against the 3 fields using basic queries.

luckytaxi