{"size": 860, "ext": "js", "max_stars_repo_path": "jstests/core/capped_queries_and_id_index.js", "max_stars_repo_name": "gaboull/mongodb-legacy", "max_stars_repo_stars_event_min_datetime": "2019-10-10T06:41:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-10T06:41:01.000Z", "max_issues_repo_path": "jstests/core/capped_queries_and_id_index.js", "max_issues_repo_name": "gaboull/mongodb-legacy", "max_issues_repo_issues_event_min_datetime": "2019-02-22T10:05:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-26T00:20:23.000Z", "max_forks_repo_path": "jstests/core/capped_queries_and_id_index.js", "max_forks_repo_name": "gaboull/mongodb-legacy", "max_forks_repo_forks_event_min_datetime": "2018-11-29T07:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-07T01:33:41.000Z"}
{"max_stars_count": 1, "max_issues_count": 4, "max_forks_count": 10, "avg_line_length": 35.8333333333, "max_line_length": 96, "alphanum_fraction": 0.6244186047}
// Tests the behavior of querying or updating a capped collection with and without an _id index.
(function() {
    "use strict";
    const coll = db.capped9;
    coll.drop();

    assert.commandWorked(db.createCollection("capped9", {capped: true, size: 1024 * 50}));

    assert.writeOK(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.writeOK(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.writeOK(coll.update({_id: 1}, {$set: {y: 5}}));
    assert.eq(5, coll.findOne().y);
}());
