Which SchemaType in Mongoose is Best for Timestamp?

后端 未结 6 1773
予麋鹿
予麋鹿 2020-12-07 16:08

I\'m using Mongoose, MongoDB, and Node.

I would like to define a schema where one of its fields is a date\\timestamp.

I would like to use this field in order

6条回答
  •  盖世英雄少女心
    2020-12-07 16:50

    In case you want custom names for your createdAt and updatedAt

    const mongoose = require('mongoose');  
    const { Schema } = mongoose;
    
    const schemaOptions = {
      timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
    };
    
    const mySchema = new Schema({ name: String }, schemaOptions);
    

提交回复
热议问题