Looking for a database with mongoose api and nodejs?

im using nodejs and mongoose to build api, im trying to execute a search function, but it doesn't seem to be asking for anything, code.

app.get('/search', function(req,res){
    return Questions.find({text: "noodles"}, function(err,q){
        return res.send(q);

    });
});

this does not give me any results, I know that there should be at least 4 results from this query, thiers 4 documents in the questions database with the word "noodles", everything works with connecting to the database and my node server

+5
source share
1 answer

What your query does is search for documents where the property textmatches "noodles"exactly. Assuming you are trying to query for documents where the property textjust contains "noodles"somewhere, you should use a regular expression instead:

app.get('/search', function(req,res){
    var regex = new RegExp('noodles', 'i');  // 'i' makes it case insensitive
    return Questions.find({text: regex}, function(err,q){
        return res.send(q);
    });
});
+13

All Articles