Cannot read data returned from orient-db in Node js using Orentjs
Hello,
I am new to orient-db and trying to fetch data from DB in my node application . I have OrientDB 2.2.7 and orientjs 2.2.x.
- I have a function (Javascript ) that returns data from the DB. getlist : { return orient.getDatabase().query("select from user where _id = ?", uId ); }
- I have used orientjs to call the function as odb.open().then(function () { { return commonjs.odb.query('SELECT getList(:uId, :vId, :mine , :pageNo , :limit)', { params: { uId: userId, vId: VUID, mine: all, pageNo: offset, limit: limit } }).then(function (res) { console.log(JSON.stringify(res)); }
- When I try to stringify the result I get error TypeError: Converting circular structure to JSON How do i get data returned from the function ?
Please help ..
Hi @gprasadg
can post here the result set of the query executed from Studio (2)?
Which is your data model?
does it works if you run directly (1) ?
Thanks Enrico
Hi Enrico,
- this is out put from Studio
{
"result": [
{
"@type": "d",
"@rid": "#-2:1",
"@version": 0,
"getList": [
{
"@type": "d",
"@rid": "#-2:0",
"@version": 0,
"_id": "Efs3CocpxFcaB3SS4",
"name": "[email protected]",
"photoUrl": "",
"ojjs": 9
}
]
}
],
"notification": "Query executed in 0.286 sec. Returned 1 record(s)"
}
- Entity is a graph entity
- yes it runs if executed directly.
- I get a circular structure object, when function is executed through orient js odb.query api.
I have same problem, please suggest how to parse query result. its blocker for us.
We still have problem to parse query results while calling simple select query or server side javascript function. ex. I have following result when i call Javascript function:
"result": [
{
"@type": "d",
"@rid": "#20:3",
"@version": 14,
"@class": "User",
"_id": "L7emzMnY9JEYsqjPp",
**"in_ShareVGame":
[{
"uName": "[email protected]",
"uEmail": "[email protected]",
"uUsername": "[email protected]",
"uPhoto": "null",
"@fieldTypes": "in_ShareVGame=g"},
{
"uName": "[email protected]",
"uEmail": "[email protected]",
"uUsername": "[email protected]",
"uPhoto": "null",
"@fieldTypes": "in_ShareVGame=g"},
}]**
}
I want to parse data from in_ShareVGame. but when I try in my node js code its no success.
There is no simple help available or an example, and its blocker for orientDB developers, please give an sample nodejs example how to parse query result. ex, if i get list of users and then i have to bind it to in HTML UI. trust me that will be great guidance for developers.
http://stackoverflow.com/questions/35346193/how-to-use-array-results-from-orientjs-query-in-another-query-array-is-not-an
@gprasadg
I don't see any recursion in you dataset let me check with function call.
@suyogdilipkale
what did you try?
Tried to parse as json. But no luck. Now thinking to use their HTTP API On Aug 26, 2016 12:24 PM, "Enrico Risa" [email protected] wrote:
@suyogdilipkale https://github.com/suyogdilipkale
what did you try?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/orientechnologies/orientjs/issues/197#issuecomment-242645247, or mute the thread https://github.com/notifications/unsubscribe-auth/APbznF-D_eszFlm95hdbFbEIJxIScubSks5qjo2mgaJpZM4Jsv5G .
@suyogdilipkale
can you share some code?
did you try as suggested in SO ?
here is sample node code:
db.open().then(function () {
console.log('db connection open');
db.query('SELECT in_ShareVGame(:uId,:vKId)', {
params: {
uId: "Efs3CocpxFcaB3SS4",
vKId:'672818a1-d163-dcd8-dab2-2a45c385207f'
}
}).then(function (response) {
var allUsers = response[0];
var firstUser =allUsers.in_ShareVGame[0];
});
});
Here I want to list all records from list, in code I have tried to parse 1st record.
@gprasadg @suyogdilipkale
i'm not able to reproduce, can you help me with a little test case or something like that?
Thanks, Enrico
Can please paste your sample server function and nodejs client code? On Aug 29, 2016 6:49 PM, "Enrico Risa" [email protected] wrote:
@gprasadg https://github.com/gprasadg @suyogdilipkale https://github.com/suyogdilipkale
i'm not able to reproduce, can you help me with a little test case or something like that?
Thanks, Enrico
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/orientechnologies/orientjs/issues/197#issuecomment-243121428, or mute the thread https://github.com/notifications/unsubscribe-auth/APbznFqUjVcpIZ0GWpG4KTf22SbTSGeVks5qktx_gaJpZM4Jsv5G .
@suyogdilipkale
this is the code i tested.
https://gist.github.com/maggiolo00/22e7f1001f35a42c42ab941b6b4ef4ac
i create a server side function and then invoke it in a select.
You hv just returned the query results, can you please just parse those list fields and console in for loop? Just to confirm all fields are displayed.
Try with some traversed query response. On Aug 29, 2016 8:30 PM, "Enrico Risa" [email protected] wrote:
@suyogdilipkale https://github.com/suyogdilipkale
this is the code i tested.
https://gist.github.com/maggiolo00/22e7f1001f35a42c42ab941b6b4ef4ac
i create a server side function and then invoke it in a select.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/orientechnologies/orientjs/issues/197#issuecomment-243150176, or mute the thread https://github.com/notifications/unsubscribe-auth/APbznFK3miDx6Qu1qXExnPOqabUHyebpks5qkvP6gaJpZM4Jsv5G .
@suyogdilipkale
can you modify my script in order to reproduce your issue?
I am getting following error: [image: Inline image 1]
Regards, Suyog Kale +91 9767654573
On Mon, Aug 29, 2016 at 9:15 PM, Enrico Risa [email protected] wrote:
@suyogdilipkale https://github.com/suyogdilipkale
can you modify my script in order to reproduce your issue?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/orientechnologies/orientjs/issues/197#issuecomment-243163896, or mute the thread https://github.com/notifications/unsubscribe-auth/APbznD5IB1reMVDaTrqYHdYxow3Bq0R_ks5qkv6xgaJpZM4Jsv5G .
Here is snapshot of that error, please help:

@suyogdilipkale
can you send me an example db with a faulty query at [email protected]? Thanks Enrico
@maggiolo00 I have already shared sample code couple of times in previous posts, I dont knw what else want to see?
FYI I have also tried with your sample code with my remote database, then I got following error:

@suyogdilipkale
i just want to replicate it. I don't have the dataset that along with your query produce that error
@gprasadg
can you help me on this?
how can i replicate it?
@gprasadg
any news on this?
I too am having issues with this. I'm simply doing a select query on the database, which fetches a list of edges. It started giving me a RangeError when trying to send the response as JSON using Socket.IO. I tried parsing it using JSON.stringify() but I'm getting a TypeError: Converting circular structure to JSON.
Hi @TheAdamGalloway
can you isolate a dataset so i can replicate the issue?
@maggiolo00 I can't get a sample dataset at the minute but I'll show an example.
So I have four classes (A, B, C & D). A is a normal class that inherits from E (EDGE) class. B and C inherit from A (so, they are edges). D is my Users class (inheriting from V).
I am querying A directly, with a fetchplan of 'in:0 out:0' and returning this. I am only working with a small dataset since I am rolling out a new feature (e.g. around 5 edges in A and B), yet I am getting a 'Maximum Call Stack size exceeded' error. This is apparently due to Circulars in the JSON, but I am unable to find any.
I have tried to parse the JSON to no avail (hence why I am getting the Circulars error). I'm not sure what else I can try.
@maggiolo00 I had a look at this bug again today, and noticed that it wasn't an issue when I omitted the fetchplan, like I had guessed. It appears that the fetched in and out vertices contain Circulars?
@TheAdamGalloway could be yes. In case of relationship that object three could became a graph and the stringify complains. I would like to replicate it so i can think of a possible solution. Thanks
@maggiolo00
I've tried using both the query builder and db.query() but both cause errors when used with a fetchplan.
e.g. db.select() .from('A') .fetch({ in: 0, out: 0 })
and db.query('select * from A', { offset: offset, limit: 10 // fetchPlan: 'in_:-1 out_:-1' })
@TheAdamGalloway
i'm looking for a solution but seems there is not easy way to fix this. The problem is that by enabling fetch plan you are actually creating a graph of objects and when serialized gives you circular JSON. Since results are javascript plain objects and we do not override JSON.stringify, you should do something like this to prevent circular exception.
var cache = {};
var json = JSON.stringify(result, function (key, value) {
if (value && typeof value === 'object' && value["@rid"]) {
if (cache[value["@rid"]]) {
return value["@rid"];
}
cache[value["@rid"]] = value;
}
return value;
});
console.log(json);
where result is the result from the query with fetch plan
@gprasadg
you should use also this approach.
@maggiolo00 That was my initial solution, since it was suggested on StackOverflow, but I thought that there may be a better way of doing it.
Thanks for the tip though. I've never had this issue when querying vertices using a fetchplan, only since I have started querying edges...
Thanks for the help!