Commit 7e2b3f18 by Wes Freeman

Merge pull request #31 from nitindhar7/master

Made sort configurable with the original value as the default. Now it ca...
parents b6e805d3 e97da335
......@@ -94,6 +94,14 @@ One can apply a "query" contraint, which takes a standard Mongo query object, to
$ mongo test --eval "var collection = 'users', query = {'caredAbout':true}" variety.js
### Analyze Documents Sorted in a particular order ###
Perhaps you want to analyze a subset of documents sorted in an order other than creation order, say, for example, sorted by when documents were updated.
One can apply a "sort" constraint, which analyzes documents in the specified order like so:
$ mongo test --eval "var collection = 'users', sort = { updated_at : -1 }" variety.js
##### "But my dad told me MongoDB is a schemaless database!" #####
First of all, your father is a great guy. Moving on...
......
......@@ -60,6 +60,9 @@ print("Using limit of " + limit);
if (typeof maxDepth === "undefined") { var maxDepth = 99; }
print("Using maxDepth of " + maxDepth);
if (typeof sort === "undefined") { var sort = {_id: -1}; }
print("Using sort of " + tojson(sort));
varietyCanHaveChildren = function (v) {
var isArray = v &&
typeof v === 'object' &&
......@@ -185,7 +188,7 @@ var addVarietyResults = function(result) {
}
// main cursor
db[collection].find(query).sort({_id: -1}).limit(limit).forEach(function(obj) {
db[collection].find(query).sort(sort).limit(limit).forEach(function(obj) {
var recordResult = {};
for (var key in obj) {
if(obj.hasOwnProperty(key)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment