Insert Into Array at Specific Position

51 views
Skip to first unread message

Michael MacFadden

unread,
Mar 29, 2015, 1:45:50 PM3/29/15
to orient-...@googlegroups.com
Hello,

Suppose I have a document that looks like this:

{
   "key": "value"
   "colors: ['red', 'yellow', 'blue']
}

What I would like to do is write a simple insert or update statement that will allow me to add the element "green" to the colors array at position 2.  The resulting document would look like this:

{
   "key": "value"
   "colors: ['red', 'yellow', 'green', 'blue']
}

A further constraint is that the actual data in the array is very larger, so I do not want to read the entire array out, add an element in code, and then write it back to the parent document.  I would really like to be able insert the element into the existing array in the database.  I took a look at the "UPDATE ADD" syntax but was unable to figure this out.

Thanks!

~Michael

Michael MacFadden

unread,
Mar 31, 2015, 4:22:39 PM3/31/15
to orient-...@googlegroups.com
I would add that I have been able to do this from the Java API using the OTrackedList API.  However, I am interested in doing this in SQL.

Thanks.

Michael MacFadden

unread,
Apr 22, 2015, 11:10:12 AM4/22/15
to orient-...@googlegroups.com
Hello,

I wanted to clarify the question also a bit.  The main issue here is that we occasionally have large documents.  Often the large documents are primarily under an array.  The array might hundreds of elements in it.  I do not want to have to load the entire array in to memory, just to get ahold of the OTrackedList instance, insert the element, and then save the whole array back.  Essentially I want to say "insert this object at position 20 in the array already in the document".  Hopefully this would avoid loading the entire array and all of its elements.

I should also comment to say that we are not entirely in control of the data structures that our clients will be putting in, and I can't force them to actually make the array contain pointers to other documents.

Is there a better place to ask this question?  We are really interested in using Orient DB, perhaps even getting an production license, but this is a bit of a show stopper at the moment.

Thanks.
Reply all
Reply to author
Forward
0 new messages