WebFund 2016W: Assignment 4
This assignment is still being developed.
In this assignment you will create queryLogs.js, a program that will query the logs collection in the log-demo database for matching log entries. Please submit your answers as a single JavaScript source file called "<username>-queryLogs.js" (where username is your MyCarletonOne username). Please do not submit a zip file (i.e., no need for a node_modules directory).
In total, there are 10 points. The questions below will be automatically graded, so please follow the directions carefully.
This assignment is due March 2, 2016.
Syntax
queryLogs.js should be called as follows:
node queryLogs.js [--output=<output file>] [--maxcount=<max number of documents to return>] <criteria> [<projection>]
Here is an example of a query that includes all the options:
node queryLogs.js --output=out.txt --maxcount=10 '{"date": "Feb 17"}' '{"message": 1}'
The above would return at most 10 matching documents and output them to out.txt. The documents would consist of all those with a date of "Feb 17", with only the message field being returned (i.e, the projection). The format of the output should be the same as the format returned from calling toArray on the find() query (see Key Logic below) - an array of JSON objects.
Arguments
- The query is mandatory. It should be a single string that follows the syntax of a find() criteria object except that the enclosing curly braces are optional.
- The output file should default to standard out.
- If no maxcount is specified then all matching documents should be returned.
- The projection should default to all fields. The enclosing braces on the object should also be optional.
Key logic
To process the query and projection strings you should:
- add enclosing curly braces if they are not present,
- convert the string to an object using JSON.parse(), and then
- create a cursor object using find(), giving it the supplied criteria and optionally the projection object, and
- retrieve all of the objects using toArray() on the cursor object (see examples of toArray() here).
- report an error message to standard error saying "Error..." (start with the word Error and say whatever afterwards) if there are any problems with the operation.
Scoring
Points will be awarded as follows:
- 3 for doing the default find() properly using a query with braces
- 1 for handling missing curly braces
- 1 for --output working properly
- 2 for limiting the records correctly
- 2 for the projection (returning only certain fields)
- 1 for handling missing or malformed queries
Total: 10 points