Created
November 16, 2017 13:38
-
-
Save terakilobyte/30402cef2aeed9e07b35ee0d05d0b94b to your computer and use it in GitHub Desktop.
validatePipeline1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validateLab1 (pipeline) { | |
var aggregations = db.getSiblingDB("aggregations") | |
if (!pipeline) { | |
print("var pipeline isn't properly set up!") | |
} else { | |
var studentSubmission = aggregations.movies.aggregate(pipeline) | |
try { | |
var keys = Object.keys(Object.getPrototypeOf(studentSubmission)).length | |
var batchSize = studentSubmission._batch.length | |
var totalReturned = studentSubmission.itcount() | |
var data = studentSubmission | |
.toArray() | |
.reduce( | |
(acc, curr) => acc + (curr.year * batchSize - curr.viewerVotes), | |
totalReturned | |
) | |
if (totalReturned === 23) { | |
print("Answer is", data % keys) | |
} else { | |
print("You aren't returning the correct number of documents") | |
} | |
} catch (e) { | |
if (e instanceof TypeError && e.message.includes("batch is undefined")) { | |
print("It doesn't appear you're using the aggregation framework") | |
} else { | |
print(e.message) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment