Retrieving a JSON document
We can perform the retrieval operation using the find method on a selected collection. Let us perform this operation by continuing with the add customers functionality and providing a list of already added customers on successful response. So, to demonstrate it, consider the following code:
{ method: 'POST', path: '/customer/add', handler(request, h){ const dbInstance = request.dbInstance; const requestBody = request.payload; const customerCollection = dbInstance.collection('customer'); return customerCollection.insert(requestBody) .then((insertedStatus) =>{ return customerCollection.find( {}) .toArray() .then((customerList) =>{ return { message: "customer added successfully", customerList } }) ...