J
J
Jeracsus2021-02-25 21:11:38
MongoDB
Jeracsus, 2021-02-25 21:11:38

How to resolve error E11000 in mongoose js?

Hello!
I encountered a non-standard error...
What's the point, when I save the user object I get an error E1100 with this comment

E11000 duplicate key error collection: f5alert.users index: apikey_1 dup key: { apikey: null }
...
code: 11000,
  keyPattern: { apikey: 1 },
  keyValue: { apikey: null }

The problem is that I simply do not have the apikey field
const id = ctx.message?.from.id

        const newUser = new User({
            tel_id: id,
            appState: {
                action: ACTIONS.WAITING,
                payload: {}
            }
        })
        ctx.reply(`Привіт, я покликаний сповіщати про надходженяя нових ремонтів! 
Щоб розпочати процес налаштування напиши /setup`)
        await newUser.save()
        // console.log('user data', {
        //     tel_id: id,
        //     appState: {
        //         action: ACTIONS.WAITING,
        //         payload: {}
        //     }
        // });

This is what console.log() returns
user data { tel_id: *сдесь ID телеграм которое 100% уникальное*, appState: { action: 'WAITING', payload: {} } }

What I just did not try, but I can not understand where this apikey came from
Help !!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Pavlenko, 2017-11-11
@Akdmeh

Not ox7FFFFFFF, but 0x7FFFFFFF (that is, the first is zero)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question