diff options
author | Adam Midvidy <amidvidy@gmail.com> | 2016-02-16 13:53:45 -0500 |
---|---|---|
committer | Adam Midvidy <amidvidy@gmail.com> | 2016-02-16 13:53:45 -0500 |
commit | 62ebc18691ef982d15506d8e50204c5a32897e5f (patch) | |
tree | 65324f726e218c3d6ca39317305cfecdcf506b9d /jstests/readonly/aggregate.js | |
parent | 1c7404095583a712d9e946e2751572c8973f13aa (diff) | |
download | mongo-62ebc18691ef982d15506d8e50204c5a32897e5f.tar.gz |
SERVER-22354 add more coverage of basic functionality to readOnly suite
Diffstat (limited to 'jstests/readonly/aggregate.js')
-rw-r--r-- | jstests/readonly/aggregate.js | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/jstests/readonly/aggregate.js b/jstests/readonly/aggregate.js new file mode 100644 index 00000000000..3bfaeab6a20 --- /dev/null +++ b/jstests/readonly/aggregate.js @@ -0,0 +1,98 @@ +load('jstests/readonly/lib/read_only_test.js'); + +runReadOnlyTest(function() { + 'use strict'; + return { + name: 'aggregate', + + load: function(writableCollection) { + assert.doesNotThrow(() => { writableCollection.insertMany([ + {award: "Best Picture", + nominations: [ + {title: "The Big Short"}, + {title: "Bridge of Spies"}, + {title: "Brooklyn"}, + {title: "Max Max: Fury Road"}, + {title: "The Martian"}, + {title: "The Revenant"}, + {title: "Room"}, + {title: "Spotlight"} + ] + }, + {award: "Best Actor", + nominations: [ + {title: "Trumbo", + person: "Bryan Cranston"}, + {title: "The Martian", + person: "Matt Damon"}, + {title: "The Revenant", + person: "Leonardo DiCaprio"}, + {title: "Steve Jobs", + person: "Michael Fassbender"}, + {title: "The Danish Girl", + person: "Eddie Redmayne"} + ] + }, + {award: "Best Actress", + nominations: [ + {title: "Carol", + person: "Cate Blanchett"}, + {title: "Room", + person: "Brie Larson"}, + {title: "Joy", + person: "Jennifer Lawrence"}, + {title: "45 Years", + person: "Charlotte Rampling"}, + {title: "Brooklyn", + person: "Saoirse Ronan"} + ] + }, + {award: "Best Supporting Actor", + nominations: [ + {title: "The Big Short", + person: "Christian Bale"}, + {title: "The Revenant", + person: "Tom Hardy"}, + {title: "Spotlight", + person: "Mark Ruffalo"}, + {title: "Bridge Of Spies", + person: "Mark Rylance"}, + {title: "Creed", + person: "Sylvester Stallone"} + ] + }, + {award: "Best Supporting Actress", + nominations: [ + {title: "The Hateful Eight", + person: "Jennifer Jason Leigh"}, + {title: "Carol", + person: "Rooney Mara"}, + {title: "Spotlight", + person: "Rachel McAdams"}, + {title: "The Danish Girl", + person: "Alicia Vikander"}, + {title: "Steve Jobs", + person: "Kate Winslet"} + ] + } + ]); }); + }, + exec: function(readableCollection) { + + // Find titles nominated for the most awards. + var mostAwardsPipeline = [ + {$unwind: "$nominations"}, + {$group: { + _id: "$nominations.title", + count: {$sum: 1}}}, + {$sort: {count: -1}}, + {$limit: 2} + ]; + + assert.docEq(readableCollection.aggregate(mostAwardsPipeline).toArray(), [ + {_id: "The Revenant", count: 3}, + {_id: "Spotlight", count: 3} + ]); + } + }; +}()); |