0
votes

as working on node.js, I have a collection called IoTCollection contains one document

{id: 1, sensor: 12 }

I need to store the returned data into a variable

var my data = db.query('FOR sensor in IoTCollection return sensor.sensorType');

but it returns a pending promise

How should I do?

Thank you in advance

1
Did the answer work for you? if yes, can you mark it 'accepted'? If not, whats missing?dothebart

1 Answers

3
votes

What exactly is your question?

All async methods in arangojs return promises. These promises will resolve to the server response (or in the case of queries: a cursor object with more async methods) eventually. In case of an error, the promises should be rejected with a specific error object indicating the problem.

If the promise is not being resolved or rejected at all, that is likely a bug.

If you're not familiar with promises I recommend reading a tutorial like David Walsh's first. A promise represents a function result (or error) that isn't known at the time the function returns (but will become known eventually). Promises are a new language feature introduced in JavaScript last year, so I recommend you get used to them.

If you're wondering why arangojs has async methods rather than being fully synchronous (like ArangoDB's internal JavaScript functions): all network access in Node.js (and the browser) is asynchronous, so arangojs can't provide a synchronous API on top of the underlying async API. To learn more about why ArangoDB is sync but Node is async, I recommend taking a look at the ArangoDB Foxx webinar.