Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SERVER-1587 add tests

  • Loading branch information...
commit 74086c6f40a39a34b3ba034ed82b695cc4758f37 1 parent d8f79a5
@astaple astaple authored
Showing with 41 additions and 0 deletions.
  1. +21 −0 jstests/exists3.js
  2. +20 −0 jstests/exists4.js
View
21 jstests/exists3.js
@@ -0,0 +1,21 @@
+// Check exists with non empty document, based on SERVER-2470 example.
+
+t = db.jstests_exists3;
+t.drop();
+
+t.insert({a: 1, b: 2});
+
+assert.eq( 1, t.find({}).sort({c: -1}).itcount() );
+assert.eq( 1, t.count({c: {$exists: false}}) );
+assert.eq( 1, t.find({c: {$exists: false}}).itcount() );
+assert.eq( 1, t.find({c: {$exists: false}}).sort({c: -1}).itcount() );
+
+// now we have an index on the sort key
+t.ensureIndex({c: -1})
+
+assert.eq( 1, t.find({c: {$exists: false}}).sort({c: -1}).itcount() );
+assert.eq( 1, t.find({c: {$exists: false}}).itcount() );
+// still ok without the $exists
+assert.eq( 1, t.find({}).sort({c: -1}).itcount() );
+// and ok with a convoluted $not $exists
+assert.eq( 1, t.find({c: {$not: {$exists: true}}}).sort({c: -1}).itcount() );
View
20 jstests/exists4.js
@@ -0,0 +1,20 @@
+// Check various exists cases, based on SERVER-1735 example.
+
+t = db.jstests_exists4;
+t.drop();
+
+t.ensureIndex({date: -1, country_code: 1, user_id: 1}, {unique: 1, background: 1});
+t.insert({ date: new Date("08/27/2010"), tot_visit: 100});
+t.insert({ date: new Date("08/27/2010"), country_code: "IT", tot_visit: 77});
+t.insert({ date: new Date("08/27/2010"), country_code: "ES", tot_visit: 23});
+t.insert({ date: new Date("08/27/2010"), country_code: "ES", user_id: "and...@spacca.org", tot_visit: 11});
+t.insert({ date: new Date("08/27/2010"), country_code: "ES", user_id: "andrea.spa...@gmail.com", tot_visit: 5});
+t.insert({ date: new Date("08/27/2010"), country_code: "ES", user_id: "andrea.spa...@progloedizioni.com", tot_visit: 7});
+
+assert.eq( 6, t.find({date: new Date("08/27/2010")}).count() );
+assert.eq( 5, t.find({date: new Date("08/27/2010"), country_code: {$exists: true}}).count() );
+assert.eq( 1, t.find({date: new Date("08/27/2010"), country_code: {$exists: false}}).count() );
+assert.eq( 1, t.find({date: new Date("08/27/2010"), country_code: null}).count() );
+assert.eq( 3, t.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: {$exists: true}}).count() );
+assert.eq( 2, t.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: {$exists: false}}).count() );
+assert.eq( 2, t.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: null}).count() );
Please sign in to comment.
Something went wrong with that request. Please try again.