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

157
Visualizações
Hide all hidden mongoose methods and properties

I use nuxt 3. I have this code on my serverside.

  findAuthorByEmail(email: string, showPassword = false) {
    return Author.findOne({ email })
      .select(showPassword ? "" : "-password_hash")
      .lean();
  },

Inside my /server/api/login.post.ts i return it here:

  return {
    token,
    author,
  };

Nuxt has the feature to provide the types for my front end. What should my query look like so that my response only provides the properties which are available? If I try to use for example $isDefault then it does not work of course.

Here is also my mongoose model:

import { Document } from "mongoose";
import { AuthorI } from "~~/types";
import { conn } from "../configuration/connection";
import { authorConfig } from "../configuration/author";
import mongoose from "mongoose";
const schema = new mongoose.Schema({
  email: {
    required: true,
    type: String,
    trim: true,
    lowercase: true,
    unique: true,
  },
  password_hash: {
    type: String,
    required: true,
    trim: true,
    minlength: authorConfig.password_min_length,
  },
  name: {
    maxlength: authorConfig.name_length,
    trim: true,
    type: String,
  },
  family_name: {
    type: String,
    maxlength: authorConfig.family_name_length,
    trim: true,
  },
  description: {
    type: String,
    maxlength: authorConfig.description_length,
    trim: true,
  },
  props: {},
  username: {
    type: String,
    trim: true,
    unique: true,
    required: true,
    maxlength: authorConfig.username_length,
  },
  created: {
    type: Date,
    required: true,
    default: Date.now,
    immutable: true,
  },
  enabled: {
    type: Boolean,
    default: true,
  },
});

export const Author = conn.model<AuthorModel>("Author", schema);

interface AuthorModel extends AuthorI, Document {}

![enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

use .lean() method. check official doc mongoose lean

about 4 years ago · Juan Pablo Isaza 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