Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDb text search doesn't return a result

Tags:

mongodb

I have the following query

db.Profiles.find({  "$text" : { "$search" : "vk" } })

It gives me the following result

{
    "_id" : ObjectId("55e999a5bd1f3926586799bb"),
    "created" : ISODate("2015-09-04T13:16:21.555Z"),
    "userId" : 4790,
    "email" : "[email protected]",
    "firstName" : "",
    "lastName" : "",
    "phoneNumber" : "",
    "isUnsubscribed" : false,
    "isAboveLimit" : true,
    "status" : 0,
    "userAgent" : 0,
    "isDeleted" : false,
    "p2l" : [ 
      {
            "listId" : 31613,
            "status" : 25,
            "subscriptionDate" : ISODate("2015-09-17T14:04:33.660Z")
        }
    ],
    "countryId" : 0,
    "cf" : []
}

But the following does not

db.Profiles.find({  "$text" : { "$search" : "v" }})

There are not results.

like image 367
Vladyslav Furdak Avatar asked Sep 23 '15 14:09

Vladyslav Furdak


1 Answers

From the documentation:

The $text operator matches on the complete stemmed word. So if a document field contains the word blueberry, a search on the term blue will not match. However, blueberry or blueberries will match.

If you want to find the records that contain a v in the email field, you can do a $regex match:

db.Profiles.find({  "email" : { "$regex" : /v/ } })
like image 142
Cristian Lupascu Avatar answered Oct 03 '22 10:10

Cristian Lupascu