Vladyslav Furdak
Vladyslav Furdak

Reputation: 1835

MongoDb text search doesn't return a result

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.

Upvotes: 6

Views: 1087

Answers (1)

Cristian Lupascu
Cristian Lupascu

Reputation: 40546

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/ } })

Upvotes: 4

Related Questions