Retrieve a specific couchDB document using an external parameter

I have a couchDB database that contains various documents. These documents need to be accessed through my web application, where users can input specific words to retrieve the corresponding document from the database. This is my _design document

{
   "_id": "_design/recuperar",
   "_rev": "3-6787751eb0ed728b482ef7b06658e8da",
   "language": "javascript",
   "views": {
       "grafos": {
           "map": "function(doc) {\n    var value;\n    if (doc.nome== 'Egypt') {         \n            value = [doc.nodos, doc.links];\n            emit(doc.nome, value);       \n    }\n}"
       }
   }
}

Currently, this setup works as intended. However, I am looking for a way to make 'Egypt' a variable based on the user's search query. Is it possible to achieve this dynamically, or will I need separate views for each search/query?

Thank you!

Answer №1

If you include the user search parameter in the query like .../?user_search=foo, you can retrieve and use the variable user_search within your view. Does that sound clear to you? For more detailed information, feel free to visit this link:

Answer №2

To improve your view, simply eliminate the condition if (doc.nome== 'Egypt') and instead utilize the standard query API found at this link: ?key='Egypt'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Instructions for adding a new line in a textarea on Internet Explorer when reading from a file

I'm facing a situation where I need to display the contents of a file (let's call it abc.txt) in a textarea on a JSP page. However, when I try to do so, all the contents are displayed in one line without any line breaks or carriage returns. Inte ...

How can I automatically disable certain checkboxes when a specific radio button is selected?

Looking to disable certain checkboxes when a specific radio button is selected. For instance, selecting the first radio button with the id="pz1" should disable checkboxes with matching id values from the thisToppings array. Each radio button cor ...

Execute asynchronous functions without pausing the thread using the await keyword

When working with an express route, I need to track a user's database access without: waiting for the process to complete before executing the user's task worrying about whether the logging operation was successful or not I'm uncertain if ...

Email responses containing unidentifiable values

Currently, I am working on implementing AJAX for my contact form to send form data to the server. The objective is to have the server email me the user's information extracted from the input fields. However, I'm encountering an issue where the f ...

Retrieve the total number of hours within a designated time frame that falls within a different time frame

Having a difficult time with this, let me present you with a scenario: A waiter at a restaurant earns $15/hour, but between 9:00 PM and 2:30 AM, he gets paid an additional $3/hour. I have the 'start' and 'end' of the shift as Date obje ...

The absence of "_ssgManifest.js" and "_buildManifest.js" files in a Next.js application deployed on Google Cloud Platform was discovered

Upon opening the website, there are instances where the console displays the following errors: GET https://example.com/subpath/_next/static/9ufj5kFJf/_buildManifest.js [HTTP/3 404 Not Found 311ms] GET https://example.com/subpath/_next/static/9ufj5kFJf/_ss ...

Enhancing server-generated content with AngularJS

Is there a way to seamlessly integrate ng-repeat with static content? In other words, is it possible to send static divs and then bind them to a JavaScript array (or create an array from the content and bind it later)? I understand that one solution could ...

Chart.js encounters difficulties displaying the chart due to the data in reactjs

My goal is to utilize chartjs-2 to showcase a bar graph with data. Below is the code I've implemented: import React from "react"; import { Bar, Line, Pie } from "react-chartjs-2"; export default class App extends React.Component { constructor(pro ...

The content inside the bootstrap modal is not visible

My goal is to trigger a modal window when a specific div is clicked using bootstrap modal. However, upon clicking the div, the screen darkens but the modal body fails to appear. Code: <html> <head> <title></title> ...

Is it possible to customize the appearance of the <audio> tag when used with a playlist?

I am struggling to style an audio tag with a playlist of songs. Does anyone have any pre-made styles that I can use for a normal white MP3 player similar to the one in the picture I attached? The MP3 player I'm aiming for Current player design Her ...

Styling the background position in CSS with the :target pseudo-class

After conducting some research, I was unable to find a satisfactory answer to my question. Essentially, I am attempting to shrink my website's header when a button is clicked. Here is the CSS code: I have been experimenting with making the backgrou ...

jsawk cannot process properly formatted JSON data

I'm in the process of creating a bash script that sends a request to a server using curl, and retrieves a JSON response. I'm attempting to extract data from this object using jsawk. Here's an example of the data I want to parse: { "acco ...

Prevent Camera from Rotating Outside of Set Time Frame

In my current VR game project using THREE.js, I am attempting to constrain the camera rotation on the y-axis within specific angles to prevent users from seeing behind them. Instead, they should only be able to look left and right. Although I am uncertain ...

Adjusting font size in dynamic containers relatively

Imagine we have a slider named .outer, which adjusts its height based on the width of the viewport. Inside this slider, there is an example slide called .inner that contains some text. However, when we shrink the window width, the content in slide .inner s ...

Trouble with executing Mongoose find within an asynchronous function

Even after referring to this stack overflow solution, I still couldn't resolve my issue. The find method works perfectly when used inside a controller but not within an async function. Here is the cron job where I'm calling this function in my ...

Numerous JavaScript modules incorporated within Ember.js

I am in the process of creating a prototype Single Page Application using Ember.js. To speed up development, I am currently utilizing three separate JavaScript components: a calendar/todo list, a JavaScript clock, and a jQuery plugin. My goal is to have th ...

Bringing together the convenience of an auto slider with the precision of a

I am looking to create a slider that combines automatic sliding with the option for manual control. Ideally, the slider would change photos automatically but also allow users to manually switch using previous/next buttons or small dots. I have searched for ...

Encountering an issue when attempting to downgrade React Native version from 0.51 to 0.45

My current project requires me to downgrade due to certain third-party packages not being updated for the latest version of react-native. Specifically, I am using Xcode 9.0. Despite my efforts to downgrade the react-native version, I encountered the follo ...

Vue.js - v-for not automatically updating when assigning a new array is not functioning

I've been going through a Vue.js tutorial on YouTube: Vue.js Tutorial: Beginner to Front-End Developer https://www.youtube.com/watch?v=1GNsWa_EZdw&t=48s Most of the tutorial has been working fine for me, except for the issue with updating the nav ...

Updating the parent component of a Vue router when closing nested routes

I have a scenario where I encounter the following steps: Go to the /parent page and see the Parent component being displayed Proceed to /parent/john and witness the Child component being rendered Return back to /parent and observe the child component bei ...