0

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

Slyfer
  • 1

1 Answers1

3

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.

Alan Plum
  • 10,814
  • 4
  • 40
  • 57
  • Thank you for enlightening me ! I'm getting it – Slyfer May 02 '16 at 12:56
  • @Slyfer if this answers the question, could you mark my answer as accepted so this question no longer shows up as unanswered? Otherwise, can you tell me what is missing or what else I can do to help you? – Alan Plum May 03 '16 at 09:51