mongoose Document doesn't map a property correctly


April 2019


51 time


I have a nodeJS Server with express project with a mongoDB.

I want to map this object, coming from an endpoint:

     userId: '5ca14305e73fc8453843d3e1',
     bookingId: '29b0c5e0-e504-43bc-b5a1-9326d7d41d45'

Its defined through a class like this:

export class CreateBookerDto {
     @IsString() readonly userId: string;
     @IsString() readonly bookingId: string;

This is my actual code doing the mapping:

export interface IBooker extends Document {
    userId: string;
    bookingId: string;
    createdAt?: number;

     @InjectModel('Booker') private readonly bookerModel: Model<IBooker>
) { }

async createBooker(booker: CreateBookerDto) {
     let createdBooker = new this.bookerModel(booker);
     createdBooker.createdAt =;

This is my output from createdBooker before the save:

     _id: 5ca146e4ba2c08380c435453,
     bookingId: '29b0c5e0-e504-43bc-b5a1-9326d7d41d45' 

Where and why does he drop the properties userId and createdAt?

0 answers