Skip to content

Loading…

Incorrect ordering of associative arrays / object attributes in documents #174

Closed
andreyvk opened this Issue · 2 comments

2 participants

@andreyvk

Hi,

I am not sure if this issue is for couchdb-lucene or couchdb itself, but i'll start from reporting here.

I have a document with an attribute, which is an object /associative array, where key is a random string and value is an object. The problem i am facing is that after getting result from CouchDB server, the keys remain in order in which they were inserted. However, if I pull the same document from couchdb-lucene, then keys become sorted and so are the values. Below is the curl outputs. Notice the items attribute.

I am using CouchDB 1.2.0 with couchdb-lucene 0.9.0.

COUCHDB OUTPUT

$ curl -X GET "http://localhost:5984/beta4_dev/4dd5bf237d97d714bf2051c90c1506f2"
{
    "created_by":"16kbalq12595w904oia4oo6tzp5284r7it14e9bric4iof8998z93r8szeozWWVA",
    "location":"Home",
    "lic_code":"fp2010",
    "dated":1371168000000,
    "type":"agenda",
    "document_type":"meeting",
    "_rev":"5-b4164b41ac5d6dba519d6627f8971689",
    "modified_timestamp":1371148952485,
    "followers":[],
    "_id":"4dd5bf237d97d714bf2051c90c1506f2",
    "items":{
        "51ace226e0da6":{
            "id":"51ace226e0da6",
            "files":[],
            "search":{
                "tags":{},
                "cuids":[]
            },
            "subject":"item #1"
        },
        "3b5b094c6bb3c":{
            "id":"3b5b094c6bb3c",
            "files":[],
            "search":{
                "tags":{},
                "cuids":[]
            },
            "subject":"item #2"
        },
        "945dae472ebf9":{
            "id":"945dae472ebf9",
            "files":[],
            "search":{
                "tags":{},
                "cuids":[]
            },
            "subject":"item #3"
        }
    },
    "modified_by":"abcdefg",
    "attendee_ids":["16kbalq12595w904oia4oo6tzp5284r7it14e9bric4iof8998z93r8szeozWWVA","abcdefg"],
    "owner_id":"16kbalq12595w904oia4oo6tzp5284r7it14e9bric4iof8998z93r8szeozWWVA",
    "created_timestamp":1370284596712
}

COUCHDB-LUCENE OUTPUT

curl -X GET "http://localhost:5984/beta4_dev/_fti/_design/lucene_meeting/default?q=_id:4dd5bf237d97d714bf2051c90c1506f2&include_docs=true"
{"limit":25,"etag":"379bbdbc5547","fetch_duration":40,"q":"_id:4dd5bf237d97d714bf2051c90c1506f2","search_duration":0,"total_rows":1,"skip":0,"rows":[
    {
        "id":"4dd5bf237d97d714bf2051c90c1506f2",
        "doc":{
            "created_by":"16kbalq12595w904oia4oo6tzp5284r7it14e9bric4iof8998z93r8szeozWWVA",
            "location":"Home",
            "lic_code":"fp2010",
            "dated":1371168000000,
            "type":"agenda",
            "document_type":"meeting",
            "_rev":"5-b4164b41ac5d6dba519d6627f8971689",
            "modified_timestamp":1371148952485,
            "followers":[],
            "_id":"4dd5bf237d97d714bf2051c90c1506f2",
            "items":{
                "3b5b094c6bb3c":{
                    "id":"3b5b094c6bb3c",
                    "files":[],
                    "search":{
                        "tags":{},
                        "cuids":[]
                    },
                    "subject":"item #2"
                },
                "51ace226e0da6":{
                    "id":"51ace226e0da6",
                    "files":[],
                    "search":{
                        "tags":{},
                        "cuids":[]
                    },
                    "subject":"item #1"
                },
                "945dae472ebf9":{
                    "id":"945dae472ebf9",
                    "files":[],
                    "search":{
                        "tags":{},
                        "cuids":[]
                    },
                    "subject":"item #3"
                }
            },
            "modified_by":"abcdefg",
            "attendee_ids":["16kbalq12595w904oia4oo6tzp5284r7it14e9bric4iof8998z93r8szeozWWVA","abcdefg"],
            "owner_id":"16kbalq12595w904oia4oo6tzp5284r7it14e9bric4iof8998z93r8szeozWWVA",
            "created_timestamp":1370284596712
        },
        "score":0.3068528175354004
    }
 ]}
@rnewson
Owner

It's not "incorrect" behavior. The order of key/value pairs in an object is not a feature of JSON objects. If you care about order, use an array.

CouchDB is copying the data about verbatim, whereas CouchDB-Lucene throws it into a Map object, which preserves the key/value pairs but not the orders.

@rnewson rnewson closed this
@andreyvk

Great. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.