Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
¿Cómo puedo resolver el error "MongoError: E11000 colección de errores de clave duplicada" en Mongo? No hay duplicación

He intentado que todas las respuestas sean StackOverflow. Pero nada de esto respondió que no funciona para mí o mi pregunta, he creado una nueva colección de Mongo para un nuevo proyecto y estoy agregando datos a esta colección usando la función map().

Colección Mongo:-

 @Schema({ timestamps: true }) export class TagServiceEntity { @Prop({ type: String, default: function genUUID() { return uuidv4(); }, }) _id: string; @Prop({ type: String, required: true, trim: true, index: true, }) name: string; @Prop({ type: String, slug: 'name', unique: true }) slug: string; @Prop() tenantId: string; } export const TagServiceSchema = SchemaFactory.createForClass(TagServiceEntity);

Función de mapa: -

 async setTags(tags: Array<string>, tenantId: string): Promise<Array<string>> { if (tags.length > 0 && tags[0] !== '') { return await Promise.all( tags.map(async (tag: any) => { const isTagExist = await this.tagsService.checkTagExist(tag); if (isTagExist) { return this.tagsService.findByTagName(tag); } const newTagData = { name: tag.toString(), tenantId: 'test-tenantId-01', }; const newTag = await this.tagsService.create(newTagData); return newTag._id; }), ); } return []; }

Función DAO: -

 async create(createTagServiceDto: any) { console.log(createTagServiceDto); try { const createTags = new this.tagsModel(createTagServiceDto); const tags = await createTags.save(); if (tags) { return tags; } } catch (error) { console.log(error); throw error; } }

Este es mi error :- ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!