Skip to content

Commit 86f05c9

Browse files
committed
fix: mongoose 5.2.0 now uses countDocuments instead of count
See Automattic/mongoose@93d06a4 Closes #108
1 parent 82ba199 commit 86f05c9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/__mocks__/mongooseCommon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mongoose.connect = (async () => {
1515
const mongoUri = await mongoServer.getConnectionString(true);
1616

1717
// originalConnect.bind(mongoose)(mongoUri, { useMongoClient: true }); // mongoose 4
18-
originalConnect.bind(mongoose)(mongoUri); // mongoose 5
18+
originalConnect.bind(mongoose)(mongoUri, { useNewUrlParser: true }); // mongoose 5
1919

2020
mongoose.connection.on('error', e => {
2121
if (e.message.code === 'ETIMEDOUT') {

src/resolvers/count.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ export default function count(
3333
resolve: (resolveParams: ExtendedResolveParams) => {
3434
resolveParams.query = model.find();
3535
filterHelper(resolveParams);
36-
return resolveParams.query.count().exec();
36+
if (resolveParams.query.countDocuments) {
37+
// mongoose 5.2.0 and above
38+
return resolveParams.query.countDocuments().exec();
39+
} else {
40+
// mongoose 5 and below
41+
return resolveParams.query.count().exec();
42+
}
3743
},
3844
});
3945
}

0 commit comments

Comments
 (0)