How to use array results from orientjs query in another query - array is not an "array"

602 views Asked by At

I want to use an array-like result from a query, but am having trouble. I have:

class case extends V
class doc extends V
class filedIn extends E

So, a document is filed in a class via an edge of class filedIn.

My first query pulls a set a vertices:

.select().from('case').one().then(function(result){...

I then want to select all the filedIn edges linking to any of those case vertices, but how?

JSON.stringify(result)

{"@type":"d","@class":"matter","title":"my case","in_filedIn":["#17:7","#17:8","#17:9"],"@rid":"#12:3","@version":12}

looks like result['in_filedIn'] is an array,

but

.select().from(result['in_filedIn']).all()

gets me this error from back from the database:

Error on parsing command at position #0: Error parsing query: \nSELECT * FROM [object Object]\nEncountered \

select().from('[#17:7,#17:8,#17:9]')

(hard coded) works.

.select.from("[" + ["#17:1","#17:2].join(',') + "]").all()

also works.

but

select.from("[" + result['in_filedIn'].join(,)+"]").all()

throws

result.in_filedIn.join is not a function

I.e. whatever kind of object it is, it's not inheriting from the Array prototype.

console.log(result['in_filedIn'])

produces:

Bag { serialized: >'AQAAAAUAEQAAAAAAAAAHABEAAAAAAAAACAARAAAAAAAAAAkAEQAAAAAAAAAKABEAAAAAAAAADwAAAAA>AAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', uuid: null, _content: [ { [String: '#17:7'] cluster: 17, position: 7 }, ...

So I'm rather puzzled what to do.

I want to select all the edges whose @rid is listed in result.in_filedIn

Or have I misunderstood something?

3

There are 3 answers

3
wolf4ood On BEST ANSWER

Hi oliver in_filedIn is not an Array is a structure called RidBag in Orientjs the implementation is done in Bag.js. If yo want to get the array you should do

result['in_filedIn'].all()

to get the array.

0
Oliver Low On

The following worked, though it's a bit dirty.

.from(JSON.stringify(result['in_filedIn']).replace(/"/g,""))

I'm still looking for a better answer!

0
Zak Holt On

I had a similar problem actually. When you instantiate your db connection, there's a config field they don't list in their docs called enableRIDBags. So your config would look like: { host: 'localhost', port: 2424, username: 'blah', password: 'blooh', enableRIDBags: false } I find that it's better to just disable RIDBags as they're a bit finicky in node. The .all() trick listed above worked fine for me up until my vertices had more than 40 edges, as then they were all converted to SBTree bags instead of Embedded bags. If you check line 122 here, you'll see that they can't convert the trees to JSON when you call .all()