I tried to do this
db.users.ensureIndex({"books.title":"text", "location":"2d"})
and MongoDB refuses to create the index with this error
{
"ok" : 0,
"errmsg" : "bad index key pattern { books.title: \"text\", location: \"2d\" }: Can't use more than one index plugin for a single index.",
"code" : 67
}
Is it the case that text index cannot be together with 2d index in a compound index?
If so, what is the possible workaround to handle queries that are based on first books.title
field and then followed by location
field ?
Thank you
UPDATE :
Text index is necessary because I plan to use weighting (http://docs.mongodb.org/manual/tutorial/control-results-of-text-search/) in the near future where books.title
may become books.title
, books.about
, and books.keywords
Regarding the query, it will be something like this
db.users.find({"books.title": "eragon", location: { $near :[ 150 , 23 ]}})
that means, find users whose location is near my point who have book entitled "eragon"