orientjs
orientjs copied to clipboard
Query has different outputs in studio and orientjs db.query
When we execute the below query in orientdb studio it shows the comment with a nested json named author which has name and rid in it.
select *, $author as author from Comment let $author = (select name, @rid from User where out(WROTE_COMMENT).@rid in $parent.current.@rid ) where in(HAS_COMMENT) in [#15:2]
But when this is executed using orientjs db.query, the author property is an array with some random id.
`class: "Comment"
rid: "#28:1"
type: "d"
version: 1
author: ["#-2:0"]
comment: "comment one"
`
How can I get the same output as I get in orient studio
hi @shyamchandranmec i'm checking
@shyamchandranmec
How is your model?
Post <-> Comment <-> User?
Which record type is #15:2?
hi @maggiolo00
#15:2 is Post..
and the model is like this..
Post ----out(HAS_COMMENT)---Comment
Comment ----in(WROTE_COMMENT)---User
If you need the db dump I can give it...
hi @shyamchandranmec yes with the dump i can quickly help you This is my email [email protected] Thanks
@maggiolo00
I have sent the db dump to your mail. Thanks
@shyamchandranmec
you could use this query that is more optimized. You will not have where condition just use the graph property starting from Post rid #15:2
select *,$author.name as authorName,$author as authorRid from (select expand(out('Has_Comment')) from #15:2) let $author = in('Wrote_Comment')[0]
@maggiolo00 , Thanks for your time. I will try this out.
hi @shyamchandranmec
did you have the chance to try it out?
Hi, I was a bit busy with other tasks.. I will try this asap...
Thanks Shyam Chandran
On Mon, Feb 15, 2016 at 5:07 PM, Enrico Risa [email protected] wrote:
hi @shyamchandranmec https://github.com/shyamchandranmec
did you have the chance to try it out?
— Reply to this email directly or view it on GitHub https://github.com/orientechnologies/orientjs/issues/139#issuecomment-184176528 .
I'm getting a really odd situation as well where the query in orientdb studio returns results different than the exact same query placed inside db.query()
In particular, I have some subqueries in a LET statement but once it gets returned by orientjs in db.query(), the results of the subquery don't match the right row being returned.
However, it works fine in orientdb studio.
Can I reach out to you @maggiolo00 via email with more details?
hi @EricLin2004 yes drop me an email i will look at it tomorrow
@maggiolo00
I checked my code. I am already doing this as a workaround to this problem. What I tried to achieve is to get the user details as a separate nested json. For which I tried the query which I have asked in the question.
The output of that query is different in both studio and db.query.... Is this a bug?
@maggiolo00 Any updates on this?
hi @shyamchandranmec
which api are you using to query?
the query builder or raw query?
Try this should work with fetchplan
db.query('select *, $author as author from Comment let $author = (select name,@rid from User where out(WROTE_COMMENT).@rid in $parent.current.@rid ) where in(HAS_COMMENT) in [#15:2]',{
fetchPlan : "author:1"
})
.then(function(res){
res.forEach(function(r){
console.log(r);
});
})
hi @shyamchandranmec
did you try the solution with fetchPlan?
hi @shyamchandranmec did you try it?
hi @shyamchandranmec
Any updates?