WebFund 2015W: Assignment 5: Difference between revisions

From Soma-notes
No edit summary
No edit summary
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''This Assignment is not yet finalized'''
In this assignment you will create <tt>queryNotes.js</tt>, a program that will query the notes collection for matching notes.  Please submit your answers as a single JavaScript source file called "<username>-queryNotes.js" (where username is your MyCarletonOne username).  Please do not submit a zip file (i.e., no need for a node_modules directory).


In this assignment you will create queryNotes.js, a program that will query the notes collection for matching notes.
In total, there are 10 points. '''The questions below will be automatically graded for everything but style.'''


Please submit your answers as a single zip file called "<username>-comp2406-assign2.zip" (where username is your MyCarletonOne username).  This zip file should unpack into a directory of the same name (minus the .zip extension of course).  This directory should contain your modified version of <tt>form-demo</tt> (one version with all code changes).
This assignment is due March 2, 2015.


In addition to the points below, you also get up to 2 points for overall programming style.  In total, there are 10 points.  '''The questions below will be automatically graded for everything but style.'''
===Syntax===


This assignment is due March 2, 2015.
queryNotes.js should be called as follows:
 
  node queryNotes.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 queryNotes.js --output=out.txt --maxcount=10 '{"owner": "Alice"}' '{"content": 1}'
 
The above would return at most 10 matching documents and output them to out.txt. The documents would consist of all those owned by Alice, with only the content 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 [http://docs.mongodb.org/manual/reference/method/db.collection.find/ 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 [http://docs.mongodb.org/manual/reference/method/db.collection.find/ 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 [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse JSON.parse()], and then
* create a cursor object using [http://docs.mongodb.org/manual/reference/method/db.collection.find/ 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() [https://www.npmjs.com/package/mongodb 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
* 1 for limiting the records correctly
* 1 for the projection (returning only certain fields)
* 1 for handling missing or malformed queries
* 2 for style
Total: 10 points


  This program will take several options:
===Solutions===
* number of documents to return
* file to output documents to (defaults to standard out)
* query as a query object
* query by specific fields (title, author, substring in contents)


More specifics for automated grading will be forthcoming by end of Tuesday.
Solutions to the assignment [http://homeostasis.scs.carleton.ca/~soma/webfund-2015w/code/queryNotes.js are now available].

Latest revision as of 20:51, 28 March 2015

In this assignment you will create queryNotes.js, a program that will query the notes collection for matching notes. Please submit your answers as a single JavaScript source file called "<username>-queryNotes.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 for everything but style.

This assignment is due March 2, 2015.

Syntax

queryNotes.js should be called as follows:

 node queryNotes.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 queryNotes.js --output=out.txt --maxcount=10 '{"owner": "Alice"}' '{"content": 1}'

The above would return at most 10 matching documents and output them to out.txt. The documents would consist of all those owned by Alice, with only the content 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
  • 1 for limiting the records correctly
  • 1 for the projection (returning only certain fields)
  • 1 for handling missing or malformed queries
  • 2 for style

Total: 10 points

Solutions

Solutions to the assignment are now available.