Skip to content

Commit

Permalink
getProjection: remove mixed values if passing a JSON string
Browse files Browse the repository at this point in the history
  • Loading branch information
loris committed May 21, 2019
1 parent 0a15edb commit 33f14f2
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,9 @@ const parseJSONString = string => {
};

const getProjection = projection => {
const jsonProjection = parseJSONString(projection);
if (jsonProjection) {
return jsonProjection;
}

const fields = parseUnaries(projection, { plus: 1, minus: 0 });
const fields =
parseJSONString(projection) ||
parseUnaries(projection, { plus: 1, minus: 0 });

/*
From the MongoDB documentation:
Expand All @@ -132,7 +129,7 @@ const getProjection = projection => {
*/
const hasMixedValues =
Object.keys(fields).reduce((set, key) => {
if (key !== '_id') {
if (key !== '_id' && (fields[key] === 0 || fields[key] === 1)) {
set.add(fields[key]);
}
return set;
Expand Down

0 comments on commit 33f14f2

Please sign in to comment.