Guest User

Untitled

a guest
May 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. // SAMPLE STORED PROCEDURE
  2. function sample() {
  3. var prefix = "";
  4. var collection = getContext().getCollection();
  5. var data = collection.readDocuments(collection.getSelfLink());
  6. console.log(data);
  7. console.log(JSON.stringify(data));
  8. // Query documents and take 1st item.
  9. var isAccepted = collection.queryDocuments(
  10. collection.getSelfLink(),
  11. 'SELECT * FROM root r',
  12. function (err, feed, options) {
  13. if (err) throw err;
  14.  
  15. // Check the feed and if empty, set the body to 'no docs found', 
  16. // else take 1st element from feed
  17. if (!feed || !feed.length) {
  18. var response = getContext().getResponse();
  19. response.setBody('no docs found');
  20. }
  21. else {
  22. var response = getContext().getResponse();
  23. var body = { prefix: prefix, feed: feed[0] };
  24. response.setBody(JSON.stringify(body));
  25. }
  26. });
  27.  
  28. if (!isAccepted) throw new Error('The query was not accepted by the server.');
  29. }
Add Comment
Please, Sign In to add comment