Unrecognized pipeline stage name: '$sortByCount' in mongo db 3.4 #4882

Closed
vijay122 opened this Issue Jan 9, 2017 · 2 comments

Projects

None yet

2 participants

@vijay122
vijay122 commented Jan 9, 2017

error code : Unrecognised pipeline stage name: '$sortByCount'

mongodb version : 3.4
mongoose version : 4.7.6

I upgraded the mongo db from 3.2 to 3.4 for the new sortByCount feature, also i updated to the latest mongoose 4.7.6 version.

Error scenario in mongoose with node.js:
Package.aggregate( [ { $unwind: "$category" }, { $sortByCount: "$category" } ],function(err,data)
{
if (err) throw err;
}
error returned by mongoose : Unrecognised pipeline stage name: '$sortByCount'

Actual on mongo 3.4 :
running the below command on mongo console, gives me,
db.packages.aggregate( [ { $unwind: "$category" }, { $sortByCount: "$category" } ] )

expected results:
{ "_id" : "honeymoon", "count" : 2 }
{ "_id" : "sightseeing", "count" : 2 }
{ "_id" : "party", "count" : 1 }
{ "_id" : "grouptrips", "count" : 1 }

please let me know if this case was already covered or help me to progress. Thanks.

@vkarpov15 vkarpov15 added this to the 4.8 milestone Jan 11, 2017
@vkarpov15 vkarpov15 added the priority label Jan 11, 2017
@vkarpov15
Collaborator

Below script works fine for me:

var assert = require('assert');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

mongoose.connect('mongodb://localhost/gh4882');
mongoose.set('debug', true);

var MyModel = mongoose.model('gh4882', new Schema({ name: String }));

MyModel.aggregate([ { $unwind: "$category" }, { $sortByCount: "$category" } ],function(err,data) {
  console.log('error', err);
  process.exit(0);
});
$ node gh-4882.js 
Mongoose: gh4882.aggregate([ { '$unwind': '$category' }, { '$sortByCount': '$category' } ]) {}  
error null
$ 

To me this error sounds like mongoose is connected to a mongodb server that isn't running 3.4. Can you please double check that?

@vkarpov15 vkarpov15 added can't reproduce and removed priority labels Jan 13, 2017
@vkarpov15 vkarpov15 removed this from the 4.8 milestone Jan 13, 2017
@vijay122

it worked fine. mongo db version was still 3.2, i updated to 3.4 and it worked fine. thanks @vkarpov15 :-)

@vijay122 vijay122 closed this Jan 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment