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