In Mongodb, I have created the collection as follows.
db.test.insertMany([
{CustomerKey : "11026", FirstName : "Harold", LastName : "Sai", BirthDate : new Date("1951-10-1"),MaritalStatus : "S", Gender : "M", EmailAddress : "harold3@adventure-works.com", YearlyIncome : 30000, TotalChildren : 2, NumberChildrenAtHome : 0, EnglishEducation : "Partial College", EnglishOccupation : "Clerical", NumberCarsOwned : 2, AddressLine1 : {House_No : 2596, Area_Name: "Franklin Canyon Road"}, Phone : "1 (11) 500 555-0131", DateFirstPurchase : new Date("2011-10-1"), CommuteDistance : "1-2 Miles"} ,
{CustomerKey : "11027", FirstName : "Jessie", LastName : "Zhao", BirthDate : new Date("1952-6-5"),MaritalStatus : "M", Gender : "M", EmailAddress : "jessie16@adventure-works.com", YearlyIncome : 30000, TotalChildren : 2, NumberChildrenAtHome : 0, EnglishEducation : "Partial College", EnglishOccupation : "Clerical", NumberCarsOwned : 2, AddressLine1 : {House_No : 8211, Area_Name: "Leeds Ct."}, Phone : "1 (11) 500 555-0184", DateFirstPurchase : new Date("2011-6-1"), CommuteDistance : "5-10 Miles"} ,
{CustomerKey : "11028", FirstName : "Jill", LastName : "Jimenez", BirthDate : new Date("1951-10-9"),MaritalStatus : "M", Gender : "F", EmailAddress : "jill13@adventure-works.com", YearlyIncome : 30000, TotalChildren : 2, NumberChildrenAtHome : 0, EnglishEducation : "Partial College", EnglishOccupation : "Clerical", NumberCarsOwned : 2, AddressLine1 : {House_No : 213, Area_Name: "Valencia Place"}, Phone : "1 (11) 500 555-0116", DateFirstPurchase : new Date("2011-10-1"), CommuteDistance : "1-2 Miles"} ,
]);
Following is the output of query :(emailaddress with Harold Available)
I have set "EmailAddress" field as Text Index.
db.test.createIndex({EmailAddress : "text"})
But When i Query using the following code, there is no any output for text filter.
db.test.find({$text:{$search:"harold"}})