ParisNakitaKejser
ParisNakitaKejser

Reputation: 14831

MongoDB and fulltext search part of the word

I need to find a part of the word, if i search about len its shut find all the words there starting by len.

i'm trying to use fulltext search in MongoDB and its working well when its hit 100% words and not just a part of the words.

Have sombardy a soluion to me to get this issue to working?

Sample code there working:

db.getCollection('product').find({
    '$and' : [{
    '$text': {
        '$search' : 'lenovo', // match word
        '$caseSensitive' : false
    },
    '$text': {
        '$search' : 'y50 b50 y700', // synonym prepared
        '$caseSensitive' : false
    }
    }]
})

Sample code i want to get the same resualt:

db.getCollection('product').find({
    '$and' : [{
    '$text': {
        '$search' : 'len',
        '$caseSensitive' : false
    },
    '$text': {
        '$search' : 'y50 b50 y700',
        '$caseSensitive' : false
    }
    }]
})

Thanks for your time, and hope i can get help for this fulltext search in MongoDB

Upvotes: 0

Views: 321

Answers (1)

jarry jafery
jarry jafery

Reputation: 1036

If you want full text search in mongo then you should go with $regex by using this query will be

db.product.find({name:{$regex:/len/i}})

for more you can read the documentation as well. https://docs.mongodb.com/manual/reference/operator/query/regex/

Upvotes: 0

Related Questions