jstests/sharding/timeseries_update.js
/**
 * Confirms that a set of updates returns the expected set of documents.
 */
Confirms that a set of updates returns the expected set of documents.
Confirms that a set of updates returns the expected set of documents .
function testShardedUpdate({
    insert,
    shardKey,
    updatesMetaFieldInShardKey,
    timeseries,
    initialDocList,
    updates,
    resultDocList,
    n,
    nModified = n,
    letDoc = {},
    failCode,
    ordered = true,
}) {
    assert.commandWorked(mongos.adminCommand({enableSharding: dbName}));
    assert.commandWorked(testDB.createCollection(collName, {timeseries}));
    const coll = testDB.getCollection(collName);
    assert.commandWorked(coll.createIndex(shardKey));
    assert.commandWorked(insert(coll, initialDocList));
    assert.commandWorked(mongos.adminCommand({
        shardCollection: `${dbName}.${collName}`,
        key: shardKey,
    }));
    if (!timeseries["metaField"]) {
        failCode = [ErrorCodes.InvalidOptions];
        n = 0;
        nModified = 0;
        resultDocList = initialDocList;
    }
    if (updatesMetaFieldInShardKey) {
        failCode = [ErrorCodes.InvalidOptions, 31025];
        n = 0;
        nModified = 0;
        resultDocList = initialDocList;
    }
    const updateCommand = {update: coll.getName(), updates, ordered, let : letDoc};
    const res = failCode ? assert.commandFailedWithCode(testDB.runCommand(updateCommand), failCode)
                         : assert.commandWorked(testDB.runCommand(updateCommand));
    assert.eq(n, res.n);
    assert.eq(nModified, res.nModified);
    assert.eq(initialDocList.length, resultDocList.length);
    resultDocList.forEach(resultDoc => {
        assert.docEq(
            resultDoc,
            coll.findOne({_id: resultDoc._id}),
            "Expected document not found in result collection:" + tojson(coll.find().toArray()));
    });
    assert(coll.drop());
}
function testShardedUpdate ( { insert , shardKey , updatesMetaFieldInShardKey , timeseries , initialDocList , updates , resultDocList , n , nModified = n , letDoc = { } , failCode , ordered = true , } ) { assert . commandWorked ( mongos . adminCommand ( { enableSharding : dbName } ) ) ; assert . commandWorked ( testDB . createCollection ( collName , { timeseries } ) ) ; const coll = testDB . getCollection ( collName ) ; assert . commandWorked ( coll . createIndex ( shardKey ) ) ; assert . commandWorked ( insert ( coll , initialDocList ) ) ; assert . commandWorked ( mongos . adminCommand ( { shardCollection : ` ${ dbName } ${ collName } ` , key : shardKey , } ) ) ; if ( ! timeseries [ "metaField" ] ) { failCode = [ ErrorCodes . InvalidOptions ] ; n = 0 ; nModified = 0 ; resultDocList = initialDocList ; } if ( updatesMetaFieldInShardKey ) { failCode = [ ErrorCodes . InvalidOptions , 31025 ] ; n = 0 ; nModified = 0 ; resultDocList = initialDocList ; } const updateCommand = { update : coll . getName ( ) , updates , ordered , let : letDoc } ; const res = failCode ? assert . commandFailedWithCode ( testDB . runCommand ( updateCommand ) , failCode ) : assert . commandWorked ( testDB . runCommand ( updateCommand ) ) ; assert . eq ( n , res . n ) ; assert . eq ( nModified , res . nModified ) ; assert . eq ( initialDocList . length , resultDocList . length ) ; resultDocList . forEach ( resultDoc => { assert . docEq ( resultDoc , coll . findOne ( { _id : resultDoc . _id } ) , "Expected document not found in result collection:" + tojson ( coll . find ( ) . toArray ( ) ) ) ; } ) ; assert ( coll . drop ( ) ) ; }
Confirms that a set of updates returns the expected set of documents.
Confirms that a set of updates returns the expected set of documents .
// Updates on timeseries collections are not allowed if no metaField is defined. // Updates on sharded timeseries meta fields are only allowed as long as the field updated is // not in the shard key.