Insert and retrieval order


#1

Hi all,

Is there a way we can maintain the insertion and retrieval order same for json document.
eg.

config : {
“x” : {
“p” : 2,
“a” : 3
},
“a” : {
“b” = 23,
“l” = 56
}
}

When I store above doc and try to retrieve the same, the order of elements is getting changed.
I want the ordering to remain as is.

I understand its an object and there is no guarantee for the ordering.
But my use case is to take this doc and covert to an xml and load on the system. If ordering is not same xml load fails.

Note: I don’t want to push xml in db.

Thank you for your support.

Regards,
Kanhaiya


#2

Not through N1QL.

Try this.

  1. insert through SDKs
  2. Use covered query get the documents keys only (if u don’t know keys).
  3. Then use SDK fetch the documents.
    OR
    N1QL SELECT RAW t FROM default t USE KEYS [ "k1, “k2”] – No predicates and no processing must be used as RAW t WITH pretty=false