Skip to content

Commit 9f1304b

Browse files
committed
fix(find): use fields instead of projection for mongodb driver 2.x
1 parent dde6df2 commit 9f1304b

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

lib/collection.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ const debug = require('debug')('monogram:collection');
66
const find = require('./find');
77

88
class Collection {
9-
constructor(collection, archetype) {
9+
constructor(collection, archetype, options) {
1010
this._collection = collection;
1111
this.collection = collection.s.name;
12+
this.options = options || {};
1213
if (archetype) {
1314
this._archetype = archetype;
1415
} else {

lib/database.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Database {
2222
if (this.collections[name]) {
2323
return this.collections[name];
2424
}
25-
this.collections[name] = new Collection(this.db.collection(name), archetype);
25+
this.collections[name] = new Collection(this.db.collection(name), archetype, { isMongoDBDriver3: this.client != null });
2626
return this.collections[name];
2727
}
2828

lib/find.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ module.exports = collection => {
2222
if (chained.name === 'cursor' && chained.params.length === 0) {
2323
return;
2424
}
25-
// Special case, `project()` sets `projection` option
26-
const name = chained.name === 'project' ? 'projection' : chained.name;
25+
// Special case, `project()` sets `projection` option or `fields` depending on driver version
26+
const projectionOption = collection.options.isMongoDBDriver3 ? 'projection' : 'fields';
27+
const name = chained.name === 'project' ? projectionOption : chained.name;
2728
action.params[1][name] = chained.params[0];
2829
});
2930
return action;

0 commit comments

Comments
 (0)