Doing partial search with mongoose

mongoose-fuzzy search
mongoose partial full search
mongoose regex
mongoose text search
mongoose search query like
mongodb string replace regex
mongoose search multiple fields
mongodb regex special characters

I'm trying to get Mongoose to return results in a query when I only give a partial query. For example: I have a 'Company' schema that lists a bunch of companies. A document example:

{
"_id" : ObjectId("57aabeb80057405968de1539"),
"companyName" : "Vandelay Industries",
"owner" : "Ary Vandelay",
"inception" : 2012,
"__v" : 1
}

So if I do a search query like this:

Company.findOne(
    { companyName: Vandelay Industries }, function (err, company) {
        if (company) {
            //do stuff
        }
    });

This will produce the document. But If I do the following, I won't get a result:

Company.findOne(
    { companyName: Vandelay }, function (err, company) {
        if (company) {
            //do stuff
        }
    });

I would like to be able to do these sorts of partial searches and still get a result. Is there any way to do that with Mongoose?

In order to achieve this you can use a regex search to get the required result.

var searchKey = new RegExp('Vandelay', 'i')
Company.findOne({ companyName: searchKey }, function (err, company) {
    if (company) {
        //do stuff
    }
});

Refer this stackoverflow post.

Doing partial search with mongoose, In order to achieve this you can use a regex search to get the required result. var searchKey = new RegExp('Vandelay', 'i') Company.findOne({  How to Implement Partial Text Search using Mongoose? I’m going to use Regular expression (regex) to implement the partial text search in Mongoose. You can use another approach with match, in, or by using other operators.

You can use this query to get result on specific value

Company.findOne({"companyName": /Vandelay/},function(err,company){
    if(!err){
        console.log(company);
    }
});

Partial Text Search vs Full Text Search in mongoose, Hi i have tackled a problem in nodejs (mongo db) for search by multiple field Thats Partial Search we can do it by using regular expressions. Mongoose's findOneAndUpdate() is slightly different from the MongoDB Node.js driver's findOneAndUpdate() because it returns the document itself, not a result object. As an alternative to the new option, you can also use the returnOriginal option.

To get result faster you should use indexing ref https://docs.mongodb.com/manual/text-search/.

db.Company.createIndex( { companyName: "text" } )

then you can search

   db.Company.find( { $text: { $search: "company name" } } )

But this only support full word search not partial, so adding an extra line to this will help

   db.Company.find({ $or: [
            { $text: { $search: query } },
             { companyName: { $regex: '^' + 'copmany name'} }
          ]}

This will help you search the results faster than normal

Mongoose text-search with partial string - node.js - html, You can do this with an aggregate pipeline that concatenates the first and last names together using $concat and then searches against that: let regex = new  Mongoose, any of nearly three dozen species of small bold predatory carnivores found mainly in Africa but also in southern Asia and southern Europe. Mongooses are noted for their audacious attacks on highly venomous snakes such as king cobras.

Are you doing a fulltext search? If you do that:

TagGroup.find({
    $text: {
        $search: text
    }
}, {
    score: {
        $meta: "textScore"
    }
}).sort({
    score: {
        $meta: 'textScore'
    }
})

Try that code below. Also you need create a index on that schema

TagGroupSchema.index({
    "$**": "text"
});

Here is the document

You can use elasticsearch to do that either, when the documents grows, you should consider this way.

$regex, Specify a Language for Text Index · Specify Name for text Index · Control Search Results with Weights · Limit the Number of Entries Scanned · Wildcard Indexes. Site navigation Search Cart. Search "Close (esc)" Electrified React Series Learn More Mongoose Lowrider Scores Cover of Street Trucks Magazine. May 29, 2020.

Partial Indexes, MongoDB will not use the partial index for a query or sort operation if using the index results in an MongoDB 3.0 or earlier do not support partial indexes. Optional. The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer. If not specified, the search uses the default language of the index. For supported languages, see Text Search Languages.

How to do partial search in mongoDB or mongoose?, My User model schema is const userSchema = new mongoose.Schema( { firstname: { type: String, required: true, trim: true }, lastname: { type:  Avoid the sore back of a full DITY move but keep the essentials available with a partial PPM. AHRN.com has put together what you need to know to make the most of your partial DITY move! Eight months after I married my husband, I found myself facing a mid-deployment local move across town.

Partial and Full text Search in mongodb and node.js, As at MongoDB 3.4, the text search characteristic is planned to support case-​insensitive searches on text content with language-specific rules  Mongoosastic doesn't touch the Mongoose MongoDB find methods for searching MongoDB data and instead adds a search method which gives you access to the Elasticsearch DSL. At its simplest this can be just the terms we are looking for: Book.search({ query:terms }, function(err,results) {