Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

265
Visualizações
What are all the options that a field can have in a mongoose Schema?

So basically I am working with mongodb using mongoose. I would like to know what are all the potential options that a field can have in a mongoose schema. For example, a user schema:

const UserSchema = new Schema(
   {
      username: {
         required: true,
         unique: true,
      },
      email: {
         required: true,
         unique: true,
      },
   },
   {
      timestamps: true,
   }
);

Here the fields of the schema are username and email. The options for these fields are required and unique. What are ALL the options that a field can have in a mongoose Schema? I found schema options in the mongoose docs but it talks about autoIndex and all this other stuff that is not relevant to my question. So again my question is what are all the options that a field can have in a mongoose schema. Thank You!

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I believe all schema options are provided here: https://mongoosejs.com/docs/api/schematypeoptions.html

By any chance website goes down, there list is as follows:

cast
default
immutable
index
ref
required
select
sparse
text
transform
type
unique
validate

As you can see, both of your given options are there as well. One problem that I see is the amount of examples provided in that page. I checked some other sources and found this: https://github.com/Automattic/mongoose/blob/master/lib/schematype.js

What you would need to do is to search for a field (let's say, prototype.select or prototype.unique), find something like this: SchemaType.prototype.select = function select(val) { and check comment above it. From what I have seen, only type doesn't appear to have any example, not sure why.

over 4 years ago · Santiago Trujillo Relatório

0

Ok so me not knowing all the options kept ticking me off so I kept searching and eventually I stumbled across the part of the documentation that answered my question. So for anyone who also has this same question, go to this link: https://mongoosejs.com/docs/schematypes.html. Do a ctrl f for "All Schema Types" and you'll find them :)

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda