These are chat archives for Automattic/mongoose

21st
Aug 2018
krystal
@dejour
Aug 21 2018 03:52
what is the limit of $in operator?
krystal
@dejour
Aug 21 2018 05:41
@pakastin thanks
Dimitar Danailov
@dimitardanailov
Aug 21 2018 15:23
Hello I'm working on Microservices solution and I'm using TypeScript, Express and Mongoose. My Model has the follow definition:
import { mongoose } from "../database/config";
import { Document, Schema, Model } from "mongoose";
import { IQuery } from '../interfaces/IQuery';

interface IQueryModel extends IQuery, Document {

}

const QuerySchema: Schema = new Schema({
    'applicationId': String,
    'parseQuery': String,
    'progress': {
        'type': String,
        'percent': Number
    },
    'createdAt': Date,
    'updatedAt': Date
});

QuerySchema.pre('save', next => {
    const now = new Date();
    if (!this.createdAt) {
        this.createdAt = now;
        this.updatedAt = now;
    }
    next();
});

export class Query extends mongoose.model<IQueryModel>('Query', QuerySchema) {
}
I could save or access database records
findOne returns:
{"$__":{"strictMode":true,"getters":{},"_id":{"_bsontype":"ObjectID","id":{"0":91,"1":123,"2":229,"3":199,"4":152,"5":252,"6":14,"7":49,"8":181,"9":17,"10":15,"11":221}},"wasPopulated":false,"activePaths":{"paths":{"_id":"init","applicationId":"init","parseQuery":"init","__v":"init"},"states":{"ignore":{},"default":{},"init":{"_id":true,"applicationId":true,"parseQuery":true,"__v":true},"modify":{},"require":{}},"stateNames":["require","modify","init","default","ignore"]},"pathsToScopes":{},"emitter":{"domain":null,"_events":{},"_eventsCount":0,"_maxListeners":0},"$options":{}},"isNew":false,"_doc":{"_id":{"_bsontype":"ObjectID","id":{"0":91,"1":123,"2":229,"3":199,"4":152,"5":252,"6":14,"7":49,"8":181,"9":17,"10":15,"11":221}},"applicationId":"123456789","parseQuery":"{}","__v":0},"$init":true}
My question is how to hide all Mongoose properties from JSON response response
I found this repo: https://www.npmjs.com/package/mongoose-hidden but I don't to use. I can't find on Documentation how to tell which properties to be removed from JSON response