K
K
Konstantin2021-06-14 23:14:33
Mongoose
Konstantin, 2021-06-14 23:14:33

How to solve key pattern error?

When creating a user, I get an error:

MongoError: E11000 duplicate key error collection: app.users index: email_1 dup key: { email: null }
    at Function.create (C:\Users\Konstantin\Desktop\bot\node_modules\mongodb\lib\core\error.js:57:12)
    at toError (C:\Users\Konstantin\Desktop\bot\node_modules\mongodb\lib\utils.js:130:22)
    at C:\Users\Konstantin\Desktop\bot\node_modules\mongodb\lib\operations\common_functions.js:258:39
    at handler (C:\Users\Konstantin\Desktop\bot\node_modules\mongodb\lib\core\sdam\topology.js:943:24)
    at C:\Users\Konstantin\Desktop\bot\node_modules\mongodb\lib\cmap\connection_pool.js:350:13
    at handleOperationResult (C:\Users\Konstantin\Desktop\bot\node_modules\mongodb\lib\core\sdam\server.js:558:5)
    at MessageStream.messageHandler (C:\Users\Konstantin\Desktop\bot\node_modules\mongodb\lib\cmap\connection.js:281:5)
    at MessageStream.emit (events.js:210:5)
    at processIncomingData (C:\Users\Konstantin\Desktop\bot\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
    at MessageStream._write (C:\Users\Konstantin\Desktop\bot\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
    at doWrite (_stream_writable.js:431:12)
    at writeOrBuffer (_stream_writable.js:415:5)
    at MessageStream.Writable.write (_stream_writable.js:305:11)
    at TLSSocket.ondata (_stream_readable.js:726:22)
    at TLSSocket.emit (events.js:210:5)
    at addChunk (_stream_readable.js:308:12)
    at readableAddChunk (_stream_readable.js:289:11)
    at TLSSocket.Readable.push (_stream_readable.js:223:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:182:23) {
  driver: true,
  name: 'MongoError',
  index: 0,
  code: 11000,
  keyPattern: { email: 1 },
  keyValue: { email: null }


But in my model there is no email field and there are no plans, how to remove the error?

const mongoose = require('mongoose')
const Schema = mongoose.Schema

const UserSchema = new Schema ({
    telegramId: {
        type: Number,
        required: true
    },
    username: {
        type: String
    },
    tickets: {
        type: Number
    },
    countGames: {
        type: Number,
        default: 0
    },
    sumCost: {
        type: Number,
        default: 0
    },
    sumWin: {
        type: Number,
        default: 0
    }
})

mongoose.model('users', UserSchema)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question