-
Type: Question
-
Resolution: Gone away
-
Priority: Minor - P4
-
None
-
Affects Version/s: 4.8.0
-
Component/s: None
-
Empty show more show less
-
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.
- depends on
-
NODE-4449 Investigate NODE-4448 - Sending `insertMany()` and `createCollection()` with timeseries concurrently results in collection without timeseries
- Closed