Troubleshooting Issue with Query Functionality in MEAN App's Find Request

I'm facing some challenges while working with queries in my MEAN App.

Specifically, I am attempting to retrieve data that matches the input entered into a search field:

$scope.searchInput = function(search){
$http({
  method: 'GET',
  url: '/search',
  params: {'licensor.name' : search}
})
.success(
function(success){
       console.log(success)
})
.error(
function(error){
      console.log(error)
});
}

On the server side, my code is as follows:

app.get('/search', function(req,res){
    ImportCollection.find(function(err, imports){
        if(err) throw err
        res.json(imports)
    });
});

However, this always returns the full collection. Any thoughts on how to solve this?

Answer №1

Make sure to include the find function in your query when passing it along. If you have any parameters, be sure to include them in your request.

For instance -

app.get('/search', function(req,res){
    ImportCollection.find(req.query).exce(function(err, imports){
        if(err) throw err
        res.json(imports)
    });
});

Many thanks!

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

Removing a single object from an array of objects using MongooseJS

Hello to all the MongooseJS experts out there! I'm a newcomer to MongooseJS, and I've been trying to solve this problem for the past two days but haven't found a solution yet. Thank you in advance for any help! The Issue with My Delete me ...

Utilizing Node Js and Socket.Io to develop a cutting-edge bot

Is it possible to run JavaScript with Node.js without launching Google Chrome from various proxies? Can someone provide a sample code for this task? For example, you can find a similar project here: https://github.com/huytd/agar.io-clone Another project c ...

What is the best way to retrieve an object from a POST request using Angular AJAX calls in a NODEJS environment?

When the button is clicked, a method will be called. The code for this is as follows: .controller('templeDetailsList', function ($scope, $http, $ionicModal) { $scope.starclick = function(){ var newFav = [{ ...

Execute JavaScript function after the window has finished loading, regardless of any asynchronous downloads

In my app, there is an initialise function that I want to execute only when two conditions are met: first, the window has finished loading ($(window).load()), and second, Typekit has loaded. $(window).load(function() { try { Typekit.load({ act ...

Focus on selecting each label within a table using JavaScript

In my current setup, I am attempting to customize radio buttons and checkboxes. Array.from(document.querySelectorAll("tr")).forEach((tr,index)=>{ var mark=document.createElement("span"); Array.from(tr.querySelectorAll("input")).forEach((inp,index ...

"Include the 'unsafe' prefix at the start of the URL in AngularJS

Whenever I attempt to access app://csttree?featuretype=cst_issue&verticalid=2132321&l1=3213&l2=3242 within my app, the URL gets parsed as ==> unsafe:app://csttree?featuretype=cst_issue&verticalid=2132321&l1=3213&l2=3242 Is ...

Retrieving Files using Ajax Across Different File Types

I recently came across the following code snippet: DOM_imgDir = "img/UI/DOM/"; fileextension = ".jpg"; $.ajax({ url: DOM_imgDir, success: function (data) { $(data).find("a:contains(" + fileextension + ")").each(function () { filename = thi ...

What will occur if I invoke response.end in Node.js while asynchronous I/O operations and callbacks are still executing?

When working with Node.js, what happens if you call "response.end()" while I/O calls and/or callbacks are still being executed? Take a look at the code snippet below: var app = http.createServer(function(request, response) { response.writeHead(200, { ...

Replicating a Bootstrap element without transferring all event listeners

Recently, I posted a query on Stack Overflow regarding the cloning of a bootstrap element while excluding the copied event listener. The solution provided was to refrain from passing true to the clone() function. Upon further reflection, I've realize ...

Guide on transforming UTC time from the server to the local time of users during a GET request

I am currently facing a challenge where I need to verify if the date of the last time an element was clicked matches the current date. Due to my server generating the current date which is 5 hours ahead of my local time, there is a discrepancy causing the ...

Can you explain the parameters accepted by the Model.prototype.save() function in mongoose?

I am confused about the save function's callback in Mongoose. The documentation only mentions that it is an optional callback without providing any specific information on the parameters it accepts. This lack of clarity has left me wondering why Mongo ...

Is it feasible to utilize express.static twice in Express.js 4.x?

I am seeking to create a unique 404 page that includes HTML, CSS, images, and icons. Upon reviewing my project structure, I have observed that my 404 folder functions correctly when replacing the initial public static homepage. However, I suspect that I ma ...

Issues with JQuery script causing inconsistency in checking checkboxes

My code includes two functions designed to check and uncheck all checkboxes with a specific class. Initially, the functions work as expected but upon subsequent attempts to run them, the checkboxes do not function properly. Instead, the HTML code seems to ...

Filter peacefully based on timing

I am currently working on developing a restful API using nodejs/express. GET /articles (retrieve all articles) PUT /articles/23 (update article with id 23) GET /articles/23 (retrieve article with id 23) POST /articles (create new article) DELETE /article ...

Executing multiple bash commands in parallel using a REST API with NodeJS

I have been working on setting up an Express server with NodeJS, and I encountered a problem where an endpoint is required to run heavy bash operations. However, when this endpoint is triggered, it significantly slows down the entire server! For instance, ...

Attempting to fill a collection of JSON entities through a GET call?

When handling a GET request that contains a list of JSON objects, I want to display the data in an input field on the screen using ng-model for data binding. The structure of the JSON get request is as follows: [{"make":"Mahindra","vin":"1987","model":"XU ...

Excluding a Spec File in Your Protractor Configurations

I have a scenario where I have 10 spec files all named *********.test.js. I need to run tests on all 9 of these files, excluding the file named Idontwantyou.test.js. Currently, I am locating my spec files in the config.file using: specs: ['*.test.js ...

A beginner's guide to using Jasmine to test $http requests in AngularJS

I'm struggling with testing the data received from an $http request in my controller as I don't have much experience with Angular. Whenever I try to access $scope, it always comes back as undefined. Additionally, fetching the data from the test ...

The error message "TypeError: Cannot read property 'map' of undefined when trying to set state as an array"

Encountering an error while trying to map the state for my posts:[] object: Error message: TypeError: this.state.posts.map is not a function While searching for a solution, I found something similar on this link, but unfortunately, it did not solve the ...

Disabling the visibility of elements through a transparent sticky-top menu

I'm having an issue with my website design. I have a gradient background and a sticky-top menu on the site. The problem is that when I scroll down, the content appears through the menu, which is not ideal. I don't want to apply the same gradient ...