Description
It's the first time I am trying this library, might be pretty useful in many of my projects, however I can't figure out why it's not working at all at the moment.
That's how I define my model in TypeScript:
import * as mongoose from 'mongoose'
import * as URLSlugs from 'mongoose-url-slugs'
const mapSchema = new mongoose.Schema({
author: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
}, { timestamps: true })
mapSchema.plugin(URLSlugs('name'))
const map = mongoose.model('Map', mapSchema)
export default map
And this is the relevant snippet which is executed for upserting the documents:
const filter = { identifier: document.identifier }
const options = { runValidators: true, upsert: true }
const p = Map.findOneAndUpdate(filter, document, options)
insertPromiseArray.push(p)
The issue:
Unhandled rejection MongoError: E11000 duplicate key error collection: brawlstats.maps index: name_slug_1 dup key: { : null }
at Function.MongoError.create (C:\Users\user\Documents\project-csv-converter\node_modules\mongodb-core\lib\error.js:31:11)
at C:\Users\user\Documents\project-csv-converter\node_modules\mongodb-core\lib\connection\pool.js:497:72
at authenticateStragglers (C:\Users\user\Documents\project-csv-converter\node_modules\mongodb-core\lib\connection\pool.js:443:16)
at Connection.messageHandler (C:\Users\user\Documents\project-csv-converter\node_modules\mongodb-core\lib\connection\pool.js:477:5)
at Socket. (C:\Users\user\Documents\project-csv-converter\node_modules\mongodb-core\lib\connection\connection.js:361:20)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at addChunk (_stream_readable.js:252:12)
at readableAddChunk (_stream_readable.js:239:11)
at Socket.Readable.push (_stream_readable.js:197:10)
at TCP.onread (net.js:589:20)
It inserts exactly one document into my collection, so I assume this issue pops up because it can't insert a second document with null as key for my slug field. Why is it not sluggifying and inserting my field when I upsert documents?