Associative array in CouchDB keys?
I haven't seen any mention of this around, but is there any way to deal with an associative array key in CouchDB?:
map: function(doc) { if (...) { emit({ one: doc.one, two: doc.two, ... }); } }
I have a need for some rather dynamic and complex queries, thi开发者_开发问答s would help solve that problem (but I'm guessing this completely breaks everything).
All keys are always sorted along one dimension only. Associative array (object) keys are supported by CouchDB. The sort order is well-defined, however it is basically arbitrary and much less intuitive than, for example, arrays, where we all know that the first/leftmost element is most significant.
Additionally, different programming languages, client libraries, and JSON serializers might (and do!) change the order of the keys in the associative array. (Often it does not matter because in Javascript, or in most languages really, key order is undefined.)
The CouchDB collation specification describes the sort order of all valid JSON data, including associative arrays (objects).
Maybe you can simulate associative arrays by flattening it into an array and sorting the keys, all o the client side.
{"foo":"This value is foo", "A":65, "the":"end"}
becomes
["A", 65, "foo", "This value is foo", "the", "end"]
精彩评论