mongoose - Mongodb error "failed to use text index to satisfy $text query" -


i'm trying use fulltext search. setting index in way

myrootschema.index({ "_type": 1, "$**": "text" });  

where _type discriminatorkey , myrootschema father schema of 4 inherited schemas.

i error

{ "name": "mongoerror", "message": "error processing query: ns=mydb.casenotestree: text : query=title, language=english, casesensitive=0, diacriticsensitive=0, tag=null\nsort: {}\nproj: {}\n planner returned error: failed use text index satisfy $text query (if text index compound, equality predicates given prefix fields?)", "waitedms": 0, "ok": 0, "errmsg": "error processing query: ns=mydb.casenotestree: text : query=title, language=english, casesensitive=0, diacriticsensitive=0, tag=null\nsort: {}\nproj: {}\n planner returned error: failed use text index satisfy $text query (if text index compound, equality predicates given prefix fields?)", "code": 2 } 

trying query

model     .find(         { $text : { $search :req.query.q } }      )     .exec(function(err, data) {         if(err)res.json(err)         res.json(data)     }); 

edit: suggested, should set _type field in query, _type 'autofilled' since discriminator. query single _type works, don't need that, have query 4 inherited models. tried $or, doesn't work same error.

model     .find(         {   $or: [ { _type: 'childa' },             { _type: 'childb' },             { _type: 'childc' },             { _type: 'childd' }         ], $text : { $search :req.query.q } }      )     .exec(function(err, data) {         if(err)console.log(err)         res.json(data)     }); 

the error messages says "if text index compound, equality predicates given prefix fields?". means, in query required supply type well. query not that, uses $text part, not type part of index.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -