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

Sending `insertMany()` and `createCollection()` with timeseries concurrently results in collection without timeseries

    • Type: Icon: Question Question
    • Resolution: Gone away
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 4.8.0
    • Component/s: None
    • Not Needed

      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:
            val@karpov.io Valeri Karpov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: