Any techniques to know which JSONDocument is newly added to exisiting JSONArray Document?

Hi
I am using google proto objects that which gets converted into JSONArray document and then store into couchbase.
Something like this:
My ProtoObjec1 Array which gets converted to JSONArrayDocument is as follows
[
{
“field0”: “0”,
“field1”: “aaaaaa”,
“field2”: “bbbbbb”,
“field3”: “cccccc”,
“field4”: 1111111,
“field5”: “dddddd”
},
{
“field0”: “0”,
“field1”: “aaaaaa”,
“field2”: “bbbbbb”,
“field3”: “cccccc”,
“field4”: 2222222,
“field5”: “dddddd”
}
]

In couchbase i will store this as
Document Key: 1111
Document Value as the below JSONArrayDocument:
[{
“field0”: “0”,
“field1”: “aaaaaa”,
“field2”: “bbbbbb”,
“field3”: “cccccc”,
“field4”: 1111111,
“field5”: “dddddd”
},
{
“field0”: “0”,
“field1”: “aaaaaa”,
“field2”: “bbbbbb”,
“field3”: “cccccc”,
“field4”: 2222222,
“field5”: “dddddd”
}]

So when i do an upsert from Java SDK and add a new JSONDocument to the existing JSONArrayDocument above , i want to inject a field namely “field6” with the latest timestamp value or something similar in the new JSONDocument. added to the Array. By this i will know that this JSONDocument is added newly.(something like a dirtly flag setting)

Example output needed:
[{
“field0”: “0”,
“field1”: “aaaaaa”,
“field2”: “bbbbbb”,
“field3”: “cccccc”,
“field4”: 1111111,
“field5”: “dddddd”
},
{
“field0”: “0”,
“field1”: “aaaaaa”,
“field2”: “bbbbbb”,
“field3”: “cccccc”,
“field4”: 2222222,
“field5”: “dddddd”
},
{
“field0”: “0”,
“field1”: “aaaaaa”,
“field2”: “bbbbbb”,
“field3”: “cccccc”,
“field4”: 2222222,
“field5”: “dddddd”
“field6”: “latestTimeStampvalue” or “some-flag to know that this JSONDocument is added newly”
}
]

As this is a google proto object i am not able to add that new field6 into the object from Java side. Is there any way in couchbase by means on N1QL or something to know that which JSONDocument is recently added in the existing array?

Pls let me know your suggestions

N1QL: You can add new document at the 0th position using ARRAY_INSERT() or last using ARRAY_APPEND().
Then get based on that https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/arrayfun.html

If more than 1 u can ARRAY_APPEND() and store statpos in outside array. When nexttime appended update that.

OR
Store as nested object

{
“timestamp”: NOW_STR(),
“val”: googleobject
}

@vsr1 Thanks…Apologies for the delayed response.

if i have JsonArrayDocument in Java. and if i want to make use of that JSONArayDocument in N1QL, will i be able to use that ? I just want to make sure that JSONArrayDocument to be directly used in N1QL, so that i should check that if the elements in the JSONArrayDocument exists in the couchbase already and if a particular element exists the it should get replaced with the new element.
For Example:
Existing JSONArrayDocument in couchbase as follows:
Document Key:1111
Document Value:
[{
“field0”: “0000”,
“field1”: “aaaaaa”,
“field2”: “bbbbbb”,
“field3”: “cccccc”,
“field4”: dddddd,
“field5”: “eeeeeee”
},
{
“field0”: “1111”,
“field1”: “ffffff”,
“field2”: “ggggg”,
“field3”: “hhhhhh”,
“field4”: 2222222,
“field5”: “jjjjjjjjjj”
}]

So in Java Couchbase JDK i have like a JSONArray Document like this
[{
“field0”: “22222”,
“field1”: “aaaaaa”,
“field2”: “eeeeee”,
“field3”: “ffffffff”,
“field4”: vvvvvv,
“field5”: “qqqqqqq”
}]

I want to replace the existing JSONArray document with this,so that my new jsonarraydocument will look like this. you can see that the first element in the jsonarraydocument gets replaced with the new one, based on field1 value which is “aaaaa” that macthes.
My new/updated JSONArrayDocument is as this:
[{
“field0”: “22222”,
“field1”: “aaaaaa”,
“field2”: “eeeeee”,
“field3”: “ffffffff”,
“field4”: vvvvvv,
“field5”: “qqqqqqq”
},{
“field0”: “1111”,
“field1”: “ffffff”,
“field2”: “ggggg”,
“field3”: “hhhhhh”,
“field4”: 2222222,
“field5”: “jjjjjjjjjj”
}]

Any idea?