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

155
Views
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 answers
Answer question

0

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

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