0

I just started having this weird issue with my db.createCollection calls using the collation option. Though this section of my codebase had been in operation and untouched for years, it is now failing. I just noticed that the db.createCollection succeeds when the collation option is removed. But for these collections, the collation option is critical.

I am using the following call:

db.createCollection(collectionName, {
    collation: {
        locale: 'en_US',
        strength: 2
    }
});

And getting this error:

MongoError: BSON field 'listCollections.collation' is an unknown field.
at MessageStream.messageHandler (C:\projectsjs\fourmatic\node_modules\mongodb\lib\cmap\connection.js:261:20)
    at MessageStream.emit (events.js:209:13)
    at MessageStream.EventEmitter.emit (domain.js:476:20)
    at processIncomingData (C:\projectsjs\fourmatic\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
    at MessageStream._write (C:\projectsjs\fourmatic\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
    at doWrite (_stream_writable.js:428:12)
    at writeOrBuffer (_stream_writable.js:412:5)
    at MessageStream.Writable.write (_stream_writable.js:302:11)
    at TLSSocket.ondata (_stream_readable.js:722:22)
    at TLSSocket.emit (events.js:209:13) {
  ok: 0,
  code: 40415,
  codeName: 'Location40415',
  '$clusterTime': {
    clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 3, high_: 1647996433 },
    signature: { hash: [Binary], keyId: [Long] }
  },
  operationTime: Timestamp { _bsontype: 'Timestamp', low_: 3, high_: 1647996433 },
  name: 'MongoError'
}

Can anyone let me know why this issue just suddenly started happening with the collation option?

Stephen Isienyi
  • 1,292
  • 3
  • 17
  • 29
  • You may also include the MongoDB and the NodeJS driver versions you are working with in the post. Also, you may want to check the MongoDB JIRA if there is any such issue already being tracked. – prasad_ Mar 24 '22 at 02:26
  • I just now tried the same code with MongoDB NodeJS v12.8, NodeJS Driver v3.7.3 and MongoDB v4.2.8 - the code creates the collection with the specified collation. Its not clear what the reason is, but you may want to include additional code/information. – prasad_ Mar 24 '22 at 02:50
  • 1
    Thank you @prasad_. I upgraded to the latest NodeJS Driver and the problem went away. There is a weird interdependency going on between the `db.createCollections` and `listCollections` that hadn't been there before. – Stephen Isienyi Mar 25 '22 at 18:08

1 Answers1

0

Migrating to the latest version of MongoDB NodeJS driver corrected the issue. I am assuming certain breaking changes recently occurred either in Atlas cloud server or in the MongoDB engine.

Stephen Isienyi
  • 1,292
  • 3
  • 17
  • 29