Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

269
Vistas
Whats the proper way to ensureIndex index mongodb field on a multidimensional array?

I have data in mongodb something like so. There is a collection of cats. The cats are sorted into different categories and ranked 1 through 100. One cat might be located in 2 or more categories. There are 1000s of categories.

COLLECTION: "cats"

KEYS:

rank.category1 = 1; // ranked 1st in category #1
rank.category2 = 13; // ranked 13th in category #2
rank.category425 = 50; // ranked 50th in category #425

QUESTION: If I want to do a find() to return all "cats" that have a "rank" in "category2" where $exists => "rank.category2" what is the proper way to index this? Can I just put a simple ascending index on "rank" collection or do I need an index on all 1000+ category* keys? Is there a better way to store this information or an easier way to index it?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

How about ...

rank.categories = [1, 2, 425];
rank.category = {
    1 : 1,
    2 : 13,
    425 : 50
}

You can index db.collection.ensureIndex({"categories":1}). Now you can search through categories and get ranking of each when you find one.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda