0

I'm relatively new to webdevelopment and have been using ArangoDB for most of that limited experience. I have a basic understanding of Node.js and creating express based CRUD apps with ArangoDB as the database.

I'm getting to a point though where I'd like to have the ability to query the database from inside the client. Say I would like to have a datalist-type element where the user types words into a searchbar. I'd like the ability to query the database from there rather than having to query the database for all of its files prior to creating the datalist. I have not found a single mention though of using database queries from the client side. I can't imagine that this is not possible. Surely when I search wikipedia through the search bar and it provides me with options I didn't just receive the entire wikipedia documents list upon loading the page? Please steer me in the right direction, I don't know how to tackle this problem.

Omnia87
  • 103
  • 7
  • The first step is to do this without ArangoDB, just have your node.js server expose a REST endpoint that allows the client to perform searches, and node.js executes those searches over something simple, like a static array. When you get that working, then update that REST API endpoint to execute queries against the database where the search text of the user is a query param. – David Thomas Mar 08 '19 at 04:07
  • You misunderstand me. I know how to interact with ArangoDB using request and response. What I don't understand is how to query the database without having to first go to one of node.js endpoints with a request. How does wikipedia do this? When I load wikipedia I get a search bar that provides suggestions when I type in a word. It has millions of documents, there's no way the page loaded with references to several millions of docs just so I can get the suggestions, the page would never load. – Omnia87 Mar 08 '19 at 07:11
  • Ah, correct. What you're seeing there is the web page is looking at the onchange event of the text box the user is typing into. It usually waits for about 1 second of no more typing then it will fire off a REST call to the server and provides the value they typed. The server then returns a payload, and the web page updates the page dynamically. To see it happening, press F12 (developer tools) in your browser, look at the network tab. You'll see network calls fire off and they contain what you typed, and see the response. – David Thomas Mar 08 '19 at 07:33
  • Your issue is no different, set up that hook and get your page firing off silently in the background to node as the user types in a query, then wire that end point into arangodb. It works a treat when you get it going. – David Thomas Mar 08 '19 at 07:34
  • Ok this sounds great. I'm just not sure how to make a call to node without actually getting a page redirect. This is possible? – Omnia87 Mar 08 '19 at 09:04
  • Do I use AJAX for this? – Omnia87 Mar 08 '19 at 12:05
  • Yes, that's right. Once you feel comfortable with that and have AJAX working, then come back and integrate your ArangoDB calls. Learning how to write dynamic web pages with REST api back ends is a great skill to have. Try this link for some training assistance, depending on your technology: https://www.pluralsight.com/search?q=ajax – David Thomas Mar 09 '19 at 07:11
  • Thank you @DavidThomas you've been very helpful. Maybe write it as an answer? I can approve it :P – Omnia87 Mar 09 '19 at 08:31

1 Answers1

1

Have a look at how to build dynamic forms, this will allow you to perform AJAX style calls from the browser window to a back end REST API service. This will allow your back end web service to gather the data for the response (from ArangoDB if required), and respond with that data, most likely in a JSON format.

Your UI can then take that response and dynamically update components in your DOM so that the user can see the data injected into the page without a page reload action taking place.

https://www.pluralsight.com/search?q=ajax is a great place to start.

Alternatively you can have a look at free content like https://www.youtube.com/watch?v=tNKD0kfel6o

David Thomas
  • 2,264
  • 2
  • 18
  • 20