0

Hello i am using Node js in combination with Async. I'am trying to use an aggegrate statement to mongodb. I have succesfully execute this statement in the MongoDB shell but it does not work with Node.

The statement within Mongo Shell is:

db.stgOmniTracker.aggregate([{ $match: {State:"Solved" } },{ $group: {_id: {lastChangeWeek: "$lastChangeWeek", lastChangeYear: "$lastChangeYear"}totalCount: { $sum: "$count" }} })

The statement which i use in node is:

var  request = require("request")
    ,async = require('async')
    ,mongo = require('mongodb')
    ,d3 = require('d3')
    ,uri = 'mongodb://localhost:27017/commevents'
    ,moment = require('moment')
    ,underscore = require('underscore')
    ,actWeek = actualWeek()
    ,actMonth =  actualMonth()
    ,ftlrGroup = []
    ,fltrState = []
    ,compareWordGroup = null
    ,compareWordState = null
    ,locals = {}

exports.getTickets = function (req, res, next) {

    console.info('-------------------Get Tickets --------------------------------------------------------')

    mongo.connect(uri, function (err, db) {
        console.info('MONGODB START CHECK COLLECTIONS')
        var tasks = [  
            // Load stgOmniTracker - prepare measureSet rawtotCreatedPerWeek
            function (callback) {
                db.collection('stgOmniTracker').aggregate([ { $group: {_id: {creationWeek: "$creationWeek", creationYear: "$creationYear"}totalCount: { $sum: "$count" }} }]).toArray(function (err, rawtotCreatedPerWeek) {
                    if (err) return callback(err);
                    locals.rawtotCreatedPerWeek = rawtotCreatedPerWeek;
                    callback();
                });
            }]
        console.info('--------------- START ASYNC ------------------------')
        async.parallel(tasks, function (err) {
            if (err) return next(err);
            var rawtotCreatedPerWeek = locals.rawtotCreatedPerWeek
            db.close()
        })

I get the following error back from node:

/home/erik/git/WisdomAsAService/views/Dashboard/getTickets.js:xx
                    db.collection('stgOmniTracker').aggregate([ { $group: {_id: {creationWeek: "$creationWeek", creationYear: "$creationYear"}totalCount: { $sum: "$count" }} }]).toArray(function (err, rawtotCreatedPerWeek) {
                                                                                                                                              ^^^^^^^^^^

    SyntaxError: Unexpected identifier

Do you know how i can fix this problem?

Manny thanks,

Erik

1 Answer 1

1

Your query is not valid. It seems to me that you are basically missing a comma.

SyntaxError: Unexpected identifier usually means that you have a token at an unsuitable place which is not understood by javascript. The best(or rather the easiest) way to tackle these errors is by using a static code analyzer like eslint, flow or sonar qube.

These tools integrate well with popular editors as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.