diff options
author | U-tellus\cwestin <cwestin@10gen.com> | 2011-06-02 17:02:14 -0700 |
---|---|---|
committer | U-tellus\cwestin <cwestin@10gen.com> | 2011-06-02 17:02:14 -0700 |
commit | ffe1ea0b5e67ba187cde79087065928d4e761402 (patch) | |
tree | 1c8c163364ec93099428b83d15da45b6894ffbc2 /jstests/aggregation | |
parent | d980d6f352dd5a4e1af54a98a5a432a1ef0950a5 (diff) | |
download | mongo-ffe1ea0b5e67ba187cde79087065928d4e761402.tar.gz |
add DocumentSourceGroup for
Diffstat (limited to 'jstests/aggregation')
-rwxr-xr-x | jstests/aggregation/testall.js | 87 | ||||
-rwxr-xr-x | jstests/aggregation/utils.js | 19 |
2 files changed, 106 insertions, 0 deletions
diff --git a/jstests/aggregation/testall.js b/jstests/aggregation/testall.js index 424fb99570e..4afa58cbccf 100755 --- a/jstests/aggregation/testall.js +++ b/jstests/aggregation/testall.js @@ -455,6 +455,93 @@ var p9result = [ assert(arrayEq(p9.result, p9result), 'p9 failed');
+// simple sort
+var p10 = db.runCommand(
+{ aggregate : "article", pipeline : [
+ { $sort : {
+ title : 1
+ }}
+]});
+
+var p10result = [
+ {
+ "_id" : ObjectId("4dc07fedd8420ab8d0d4066d"),
+ "title" : "this is my title",
+ "author" : "bob",
+ "posted" : ISODate("2011-05-03T22:21:33.251Z"),
+ "pageViews" : 5,
+ "tags" : [
+ "fun",
+ "good"
+ ],
+ "comments" : [
+ {
+ "author" : "joe",
+ "text" : "this is cool"
+ },
+ {
+ "author" : "sam",
+ "text" : "this is bad"
+ }
+ ],
+ "other" : {
+ "foo" : 5
+ }
+ },
+ {
+ "_id" : ObjectId("4dc07fedd8420ab8d0d4066f"),
+ "title" : "this is some other title",
+ "author" : "jane",
+ "posted" : ISODate("2011-05-03T22:21:33.252Z"),
+ "pageViews" : 6,
+ "tags" : [
+ "nasty",
+ "filthy"
+ ],
+ "comments" : [
+ {
+ "author" : "r2",
+ "text" : "beep boop"
+ },
+ {
+ "author" : "leia",
+ "text" : "this is too smutty"
+ }
+ ],
+ "other" : {
+ "bar" : 14
+ }
+ },
+ {
+ "_id" : ObjectId("4dc07fedd8420ab8d0d4066e"),
+ "title" : "this is your title",
+ "author" : "dave",
+ "posted" : ISODate("2011-05-03T22:21:33.251Z"),
+ "pageViews" : 7,
+ "tags" : [
+ "fun",
+ "nasty"
+ ],
+ "comments" : [
+ {
+ "author" : "barbarella",
+ "text" : "this is hot"
+ },
+ {
+ "author" : "leia",
+ "text" : "i prefer the brass bikini",
+ "votes" : 10
+ }
+ ],
+ "other" : {
+ "bar" : 14
+ }
+ }
+];
+
+assert(orderedArrayEq(p10.result, p10result), 'p10 failed');
+
+
// simple matching
var m1 = db.runCommand(
{ aggregate : "article", pipeline : [
diff --git a/jstests/aggregation/utils.js b/jstests/aggregation/utils.js index ea6b0ca4c1e..5379f59233b 100755 --- a/jstests/aggregation/utils.js +++ b/jstests/aggregation/utils.js @@ -203,3 +203,22 @@ function resultsEq(rl, rr, v) { assert(!rr.length);
return true;
}
+
+function orderedArrayEq(al, ar, v) {
+ if (al.length != ar.length) {
+ if (v)
+ print('orderedArrayEq: array lengths do not match ' +
+ al + ', ' + ar);
+ return false;
+ }
+
+ /* check the elements in the array */
+ for(var i = 0; i < al.length; ++i) {
+ if (!anyEq(al[i], ar[i], v))
+ return false;
+ }
+
+ /* if we got here, everything matched */
+ return true;
+}
+
|