Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4449

Investigate NODE-4448 - Sending `insertMany()` and `createCollection()` with timeseries concurrently results in collection without timeseries

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • 1
    • Not Needed

      NODE-4448 Description
      Consider the following script:

      const { MongoClient } = require('mongodb');
      
      void async function main() {
        const client = await MongoClient.connect('mongodb://localhost:27017/test');
      
        const p1 = client.db().createCollection('User', {
          timeseries: {
            timeField: 'timestamp',
            metaField: 'metadata',
            granularity: 'hours',
          }
        });
      
        await new Promise(resolve => setTimeout(resolve, 0));
      
        const p2 = client.db().collection('User').insertMany([{ name: 'test' }]);
      
        await Promise.all([p1, p2]);
        console.log(await client.db().listCollections().toArray());
      }();
      

      Right now it errors out with:

      /home/val/Workspace/MongoDB/mongoose/node_modules/mongodb/lib/cmap/connection.js:210
                          callback(new error_1.MongoServerError(document));
                                   ^
      
      MongoServerError: Cannot create collection test.User - collection already exists.
          at Connection.onMessage (/home/val/Workspace/MongoDB/mongoose/node_modules/mongodb/lib/cmap/connection.js:210:30)
      

      I would intuitively expect this script to successfully create a timeseries collection since the `createCollection()` is sent off first. I realize this is probably a server issue rather than a Node driver issue, but I figured I'd ask here first in case I missed somewhere in the documentation that you're expected to call `createCollection()` before sending any operations if creating a timeseries collection.

            Assignee:
            bailey.pearson@mongodb.com Bailey Pearson
            Reporter:
            dbeng-pm-bot PM Bot
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: