jstests/noPassthrough/timeseries_sample.js
/**
 * Creates the collection 'coll' as a time-series collection, and inserts data such that there are
 * the given number of measurementsPerBucket (assuming there are 'nBuckets'). Returns the total
 * number of measurement documents inserted into the collection.
 */
Creates the collection 'coll' as a time-series collection, and inserts data such that there are
the given number of measurementsPerBucket (assuming there are 'nBuckets'). Returns the total
number of measurement documents inserted into the collection.
Creates the collection ' coll ' as a time - series collection and inserts data such that there are the given number of measurementsPerBucket ( assuming there are ' nBuckets ' ) . Returns the total number of measurement documents inserted into the collection .
function fillBuckets(coll, measurementsPerBucket) {
    assert.commandWorked(testDB.createCollection(
        coll.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));
    const bucketsColl = testDB.getCollection("system.buckets." + coll.getName());
    assert.contains(bucketsColl.getName(), testDB.getCollectionNames());
    let numDocs = nBuckets * measurementsPerBucket;
    const bulk = coll.initializeUnorderedBulkOp();
    for (let i = 0; i < numDocs; i++) {
        bulk.insert(
            {_id: ObjectId(), [timeFieldName]: ISODate(), [metaFieldName]: i % nBuckets, x: i});
    }
    assert.commandWorked(bulk.execute());
    let buckets = bucketsColl.find().toArray();
    assert.eq(nBuckets, buckets.length, buckets);
    return numDocs;
}
function fillBuckets ( coll , measurementsPerBucket ) { assert . commandWorked ( testDB . createCollection ( coll . getName ( ) , { timeseries : { timeField : timeFieldName , metaField : metaFieldName } } ) ) ; const bucketsColl = testDB . getCollection ( "system.buckets." + coll . getName ( ) ) ; assert . contains ( bucketsColl . getName ( ) , testDB . getCollectionNames ( ) ) ; let numDocs = nBuckets * measurementsPerBucket ; const bulk = coll . initializeUnorderedBulkOp ( ) ; for ( let i = 0 ; i < numDocs ; i ++ ) { bulk . insert ( { _id : ObjectId ( ) , [ timeFieldName ] : ISODate ( ) , [ metaFieldName ] : i % nBuckets , x : i } ) ; } assert . commandWorked ( bulk . execute ( ) ) ; let buckets = bucketsColl . find ( ) . toArray ( ) ; assert . eq ( nBuckets , buckets . length , buckets ) ; return numDocs ; }
Creates the collection 'coll' as a time-series collection, and inserts data such that there are
 the given number of measurementsPerBucket (assuming there are 'nBuckets').
Creates the collection ' coll ' as a time - series collection and inserts data such that there are the given number of measurementsPerBucket ( assuming there are ' nBuckets ' ) .