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

aggregation query broken after upgrade to Mongo 3.6.2 #120

Closed
thumbert opened this issue Feb 14, 2018 · 1 comment · Fixed by #139
Closed

aggregation query broken after upgrade to Mongo 3.6.2 #120

thumbert opened this issue Feb 14, 2018 · 1 comment · Fixed by #139

Comments

@thumbert
Copy link

Hi,

I have an example of a simple aggregation that is no longer working after upgrading mongodb from version 3.4 to 3.6.2. Here is the error:

00:00 +0: mongo 3.6.2 bug check data
00:00 +1: mongo 3.6.2 bug find max date
00:00 +1 -1: mongo 3.6.2 bug find max date [E]
{ok: 0.0, errmsg: The 'cursor' option is required, except for aggregate with the explain argument, code: 9, codeName: FailedToParse}
dart:async/future_impl.dart 22 _Completer.completeError
package:mongo_dart/src/database/db.dart 281:14 Db.executeDbCommand
===== asynchronous gap ===========================

I add a test file. Thank you for taking a look. The query runs fine in the mongo shell.

Best regards

import 'package:mongo_dart/mongo_dart.dart';
import 'package:test/test.dart';

aggTest() async {
group('mongo 3.6.2 bug', (){
List data = [
{'type': 'A', 'date': '2017-01-01'},
{'type': 'AA', 'date': '2017-01-01'},
{'type': 'B', 'date': '2017-01-02'},
{'type': 'D', 'date': '2017-01-04'},
{'type': 'C', 'date': '2017-01-03'},
];

Db db = new Db('mongodb://127.0.0.1/test');
DbCollection coll = db.collection("agg_bug");

setUp(() async {
  await db.open();
  await coll.insertAll(data);
});
tearDown(() async {
  await coll.remove();
  await db.close();
});
test('check data', () async {
  var res = await coll.count();
  expect(res, 5);
});
test('find max date', () async {
  List pipeline = [];
  pipeline.add({'\$group': {
    '_id': 0,
    'lastDay': {'\$max': '\$date'}}});
  Map res = await coll.aggregate(pipeline);
  var lastDay = res['result'][0]['lastDay'];
  expect(lastDay, '2017-01-04');
});

});
}

main() async {
await aggTest();
}

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

Successfully merging a pull request may close this issue.

2 participants