How to not select attribute in mongoose schema

Use select: false when defining an attribute of a mongoose schema, like initiator: {type:String, select: false} in the following schema for a bookmark object:

const bookmarkSchema = new Schema(
    shareableId: { type: String, select: false },
    name: { type: String, required: true },
    type: { type: String, required:  true, default: 'bookmark' },
    location: { type: String, required: true },
    description: String,
    descriptionHtml: String,
    tags: [String],
    initiator: {type:String, select: false},
    publishedOn: Date,
    sourceCodeURL: { type: String },
    userId: { type: String, ref: 'User' },
    userDisplayName: String,
    public: Boolean,
    language: String,
    lastAccessedAt: { type: Date, select: false },
    likeCount: Number,
    ownerVisitCount: { type: Number, select: false },
    youtubeVideoId: { type: String, required: false },
    stackoverflowQuestionId: { type: String, required: false },
    __v: { type: Number, select: false },
    timestamps: true,

Project: codever - File: bookmark.js

Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

Subscribe to our newsletter for more code resources and news

Adrian Matei (aka adixchen)

Adrian Matei (aka adixchen)
Life force expressing itself as a coding capable human being

routerLink with query params in Angular html template

routerLink with query params in Angular html template code snippet Continue reading