question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

full-text search on inherited schemas

See original GitHub issue

Hi, I would bring the attention on this stackoverflow question: http://stackoverflow.com/questions/36056594/mongodb-error-failed-to-use-text-index-to-satisfy-text-query

I know it’s a huge post, basically I’m trying to make a full-text search on 4 subschemas together. The compound text index is defined myRootSchema.index({ "_type": 1, "$**": "text" }) _type is the discriminatorKey.

This query should work since _type is indeed a discriminatorkey, so mongoose should ‘autofill’ that, but it doesn’t.

Model
    .find(
        { $text : { $search :req.query.q } }

    )
    .exec(function(err, data) {
        if(err)res.json(err)
        res.json(data)
    });

trying this query I get the error failed to use text index to satisfy $text query. A temporary solution could be explicitly fill _type and use parallel from async module and query each subschema like this

 async.parallel([
            function(callback){
                caseNote
                    .find({_type:'FIRST_TYPE',$text : { $search :req.query.q } })
                    .exec(function(err, data) {
                        if(err) {
                            callback(err);
                        }
                        else {
                            callback(null, data);
                        }

                    });
            },
.....#query on each other type..#
]);

but I don’t think there is a proper way to paginate those results…so I’m stuck here.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16

github_iconTop GitHub Comments

1reaction
vkarpov15commented, Apr 16, 2016

In your example, is Model the base model? If so, the discriminator won’t get ‘autofilled’ like you said, because when you query by the base model the _type field won’t get set.

Try doing:

Model
    .find(
        { _type: { $in: ARRAY_OF_ALL_TYPES } },
        { $text : { $search :req.query.q } }
    )
0reactions
vkarpov15commented, May 9, 2016

It’ll definitely index all the inherited fields, $** has nothing to do with mongoose, it’s all at the mongodb level, so it doesn’t even know about discriminators.

Yeah, building a compound index and querying by the _type field would be all about performance - if you don’t need that extra performance, I wouldn’t recommend bothering to figure it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a text index on MongoDB schema which references ...
I am trying to add an index to a certain Schema with mongoose for text searches. If I add a text index to...
Read more >
failed to use text index to satisfy $text query (if text index is ...
Hi, I have a root schema and 4 inherited schemas. The purpose is to index all the string fields of each inherited schema...
Read more >
E Full-Text Search over XML Data Without XQuery
Oracle-specific full-text search over XML data is described, including how to use Oracle SQL function contains and Oracle XPath function ora:contains.
Read more >
Enabling Schema Inheritance - Vertica
If inherited privileges are enabled for the database, you can enable inheritance of schema privileges by its tables and views, with CREATE SCHEMA...
Read more >
Ownership and user-schema separation in SQL Server
No permissions are inherited from a schema by users; schema permissions are inherited by the database objects contained in the schema. The ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found