Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full $Text $Search with meteor-aggregate throws SyntaxError: Unexpected token $ #16

Open
timtrendlier opened this issue May 2, 2015 · 0 comments

Comments

@timtrendlier
Copy link

I've been using meteorhacks:aggregate succesfully for a while now to group article search results by category, (i'm rendering these results into an accordion control that allows each category's results to open and close by clicking the header for that category name) with the various inputs affecting the query output that results in an aggregate query that looks something like this:

[{
    "$match": {
        "$or": [{
            "published": {
                "$exists": false
            }
        }, {
            "published": "false"
        }]
    }
}, {
    "$sort": {
        "category": -1,
        "pubDate": -1
    }
}, {
    "$group": {
        "_id": "$category",
        "category": {
            "$first": "$category"
        },
        "count": {
            "$sum": 1
        },
        "articles": {
            "$push": {
                "category": "$category",
                "_id": "$_id",
                "title": "$title",
                "publisherName": "$publisherName",
                "pubDate": "$pubDate"
            }
        }
    }
}]

this is used in Meteor inside collection.aggregate() and it works beautifully and much faster than my old implementation. So far so good.

Recently I was tasked with improving this to add a text search, so I set up full text indexing and rewrote my code to produce queries like this:

[{
    "$match": {
        "$or": [{
            "published": {
                "$exists": false
            }
        }, {
            "published": "false"
        }],
        $text: {
            $search: "Meteor"
        }
    }
}, {
    "$sort": {
        "category": -1,
        "pubDate": -1
    }
}, {
    "$group": {
        "_id": "$category",
        "category": {
            "$first": "$category"
        },
        "count": {
            "$sum": 1
        },
        "articles": {
            "$push": {
                "category": "$category",
                "_id": "$_id",
                "title": "$title",
                "publisherName": "$publisherName",
                "pubDate": "$pubDate"
            }
        }
    }
}]

While both of these work great on a mongo shell, with db.articles.aggregate(), the one with the $text: { $search: "Meteor" } term fails with an error:
(Note that these are both run against the same database, the issue exists locally in meteor mongo and on compose.io)

I20150501-16:55:10.893(-7)? Exception while invoking method 'getGroupedArticles' SyntaxError: Unexpected token $
I20150501-16:55:10.893(-7)?     at Object.parse (native)
I20150501-16:55:10.893(-7)?     at [object Object].Meteor.methods.getGroupedArticles (packages/mcms-articles/server/articles-server.js:73:1)
I20150501-16:55:10.894(-7)?     at [object Object].methodMap.(anonymous function) (packages/meteorhacks:kadira/lib/hijack/wrap_session.js:160:1)
I20150501-16:55:10.894(-7)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1)
I20150501-16:55:10.894(-7)?     at packages/ddp/livedata_server.js:648:1
I20150501-16:55:10.894(-7)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150501-16:55:10.894(-7)?     at packages/ddp/livedata_server.js:647:1
I20150501-16:55:10.894(-7)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150501-16:55:10.894(-7)?     at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1)
I20150501-16:55:10.894(-7)?     at packages/meteorhacks:kadira/lib/hijack/wrap_session.js:50:1

FYI, Without kadira enabled the output looks like this:

I20150501-17:10:19.905(-7)? Exception while invoking method 'getGroupedArticles' SyntaxError: Unexpected token $
I20150501-17:10:19.905(-7)?     at Object.parse (native)
I20150501-17:10:19.906(-7)?     at [object Object].Meteor.methods.getGroupedArticles (packages/mcms-articles/server/articles-server.js:73:1)
I20150501-17:10:19.906(-7)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1)
I20150501-17:10:19.906(-7)?     at packages/ddp/livedata_server.js:648:1
I20150501-17:10:19.906(-7)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150501-17:10:19.906(-7)?     at packages/ddp/livedata_server.js:647:1
I20150501-17:10:19.906(-7)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150501-17:10:19.906(-7)?     at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1)
I20150501-17:10:19.906(-7)?     at packages/ddp/livedata_server.js:546:1```

I'm still relatively new at Meteor so I'm not sure how to debug this...

Has anyone been successful using text search within aggregates?

@timtrendlier timtrendlier changed the title Full Text Search with meteor-aggregate Full $Text $Search with meteor-aggregate throws SyntaxError: Unexpected token $ May 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant