@@ -1106,7 +1106,9 @@ MongoDB.prototype.all = function all(model, filter, options, callback) {
1106
1106
fields = self . fromPropertyToDatabaseNames ( model , fields ) ;
1107
1107
1108
1108
if ( fields ) {
1109
- this . execute ( model , 'find' , query , fields , processResponse ) ;
1109
+ // convert the array of fields into a projection object see http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#find
1110
+ var findOpts = { projection : fields } ;
1111
+ this . execute ( model , 'find' , query , findOpts , processResponse ) ;
1110
1112
} else {
1111
1113
this . execute ( model , 'find' , query , processResponse ) ;
1112
1114
}
@@ -1130,6 +1132,10 @@ MongoDB.prototype.all = function all(model, filter, options, callback) {
1130
1132
} else if ( filter . offset ) {
1131
1133
cursor . skip ( filter . offset ) ;
1132
1134
}
1135
+
1136
+ var shouldSetIdValue = idIncluded ( fields , idName ) ;
1137
+ var deleteMongoId = fields || idName !== '_id' ;
1138
+
1133
1139
cursor . toArray ( function ( err , data ) {
1134
1140
if ( self . debug ) {
1135
1141
debug ( 'all' , model , filter , err , data ) ;
@@ -1138,11 +1144,11 @@ MongoDB.prototype.all = function all(model, filter, options, callback) {
1138
1144
return callback ( err ) ;
1139
1145
}
1140
1146
var objs = data . map ( function ( o ) {
1141
- if ( idIncluded ( fields , self . idName ( model ) ) ) {
1147
+ if ( shouldSetIdValue ) {
1142
1148
self . setIdValue ( model , o , o . _id ) ;
1143
1149
}
1144
1150
// Don't pass back _id if the fields is set
1145
- if ( fields || idName !== '_id' ) {
1151
+ if ( deleteMongoId ) {
1146
1152
delete o . _id ;
1147
1153
}
1148
1154
0 commit comments