Skip to content

Commit

Permalink
add filter support to find
Browse files Browse the repository at this point in the history
  • Loading branch information
birm committed May 3, 2024
1 parent cdeff6c commit 7caf1dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
17 changes: 4 additions & 13 deletions handlers/dataHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,10 @@ Mark.pointList = function(req, res, next) {
delete query.token;
var points = [];

var cursor = mongoDB.find("camic", 'mark', query, { x: 1, y: 1, _id: 0 });

cursor.each((err, doc) => {
if (err) {
return next(err);
}
if (doc) {
points.push([doc.x, doc.y]);
} else {
req.data = { points: points };
next();
}
});
mongoDB.forEach("camic", 'mark', query, false ,{ x: 1, y: 1, _id: 0 }).then((points) => {

Check failure on line 356 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Multiple spaces found before 'false'

Check failure on line 356 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space before ','

Check failure on line 356 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (18.x)

A space is required after ','

Check failure on line 356 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space after '{'

Check failure on line 356 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space before '}'

Check failure on line 356 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Multiple spaces found before 'false'

Check failure on line 356 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space before ','

Check failure on line 356 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (20.x)

A space is required after ','

Check failure on line 356 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space after '{'

Check failure on line 356 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space before '}'
req.data = { points: points.map(point => [point.x, point.y]) };

Check failure on line 357 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space after '{'

Check failure on line 357 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected parentheses around arrow function argument

Check failure on line 357 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space before '}'

Check failure on line 357 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space after '{'

Check failure on line 357 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected parentheses around arrow function argument

Check failure on line 357 in handlers/dataHandlers.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space before '}'
next();
}).catch((e) => next(e));
};


Expand Down
11 changes: 6 additions & 5 deletions service/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class Mongo {
*
* {@link https://docs.mongodb.com/manual/reference/method/db.collection.find/ Read MongoDB Reference}
*/
static async find(database, collectionName, query, transform = true) {
static async find(database, collectionName, query, transform = true, filter = {}) {
try {
query = transformIdToObjectId(query);

const collection = getConnection(database).collection(collectionName);
const data = await collection.find(query).toArray();

const data = await collection.find(query, filter).toArray();
/** allow caller method to toggle response transformation */
if (transform) {
data.forEach((x) => {
Expand All @@ -34,13 +34,14 @@ class Mongo {
};
});
}

return data;
} catch (e) {
console.error(e);
throw e;
}
}


/**
* Runs the MongoDB find() method to fetch documents with pagination.
Expand Down

0 comments on commit 7caf1dd

Please sign in to comment.