summaryrefslogtreecommitdiff
path: root/jstests/core/capped/capped_queries_and_id_index.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/capped/capped_queries_and_id_index.js')
-rw-r--r--jstests/core/capped/capped_queries_and_id_index.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/jstests/core/capped/capped_queries_and_id_index.js b/jstests/core/capped/capped_queries_and_id_index.js
new file mode 100644
index 00000000000..20dee23035e
--- /dev/null
+++ b/jstests/core/capped/capped_queries_and_id_index.js
@@ -0,0 +1,32 @@
+/**
+ * Tests the behavior of querying or updating a capped collection with and without an _id index.
+ *
+ * @tags: [
+ * requires_capped,
+ * # capped collections connot be sharded
+ * assumes_unsharded_collection,
+ * ]
+ */
+
+(function() {
+"use strict";
+const coll = db.capped9;
+coll.drop();
+
+assert.commandWorked(db.createCollection("capped9", {capped: true, size: 1024 * 50}));
+
+assert.commandWorked(coll.insert({_id: 1, x: 2, y: 3}));
+
+assert.eq(1, coll.find({x: 2}).itcount());
+assert.eq(1, coll.find({y: 3}).itcount());
+
+// SERVER-3064 proposes making the following queries/updates by _id result in an error.
+assert.eq(1, coll.find({_id: 1}).itcount());
+assert.commandWorked(coll.update({_id: 1}, {$set: {y: 4}}));
+assert.eq(4, coll.findOne().y);
+
+assert.commandWorked(coll.createIndex({_id: 1}));
+assert.eq(1, coll.find({_id: 1}).itcount());
+assert.commandWorked(coll.update({_id: 1}, {$set: {y: 5}}));
+assert.eq(5, coll.findOne().y);
+}());