-
Type: Bug
-
Resolution: Won't Do
-
Priority: Major - P3
-
Affects Version/s: 3.6.17
-
Labels:None
Description
The documentation is not complete for compound sparse unique index.
Documentation mention if the key is omitted, then it won't trigger an error.
But that's not true for compound indexes where one key (but not all) is omitted:
```javascript
const
= require('mongodb');
async function run() {
const client = await MongoClient.connect(
'mongodb://127.0.0.1',
,
);
try {
const db = await client.db('test');
await db.dropCollection('scores').catch(() =>
{ /* no-op */ });await db.dropCollection('scores-other').catch(() => { /* no-op */ }
);
await db.collection('scores').createIndex(
,
,
);
// Works
try {
await db.collection('scores').insertOne(
);
await db.collection('scores').insertOne(
);
} catch (e)
try {
// Works because key is omitted
await db.collection('scores').insertOne(
);
await db.collection('scores').insertOne(
);
} catch (e)
try {
// Not working: key is not considered as omited https://docs.mongodb.com/manual/core/index-sparse/#sparse-and-unique-properties
await db.collection('scores').insertOne(
);
await db.collection('scores').insertOne(
);
} catch (e)
} catch (err)
{ console.error(err); }finally
{ client.close(); }}
run();
```
I am not sure if this requires a documentation update or a bug fix.