How do you declare date on Node Express?

1

I have the following entity;

'use strict'

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var ReviewsSchema = Schema({

    name: String,
    date: String,
    rating: String,
    comments: String,
    restaurantId: String
});

module.exports = mongoose.model('Reviews', ReviewsSchema);

What I need is to know if I'm declaring the date attribute right, if it's not right how should I declare the date attribute?

I'm using Node Express with MongoDB.

    
asked by anonymous 03.07.2018 / 14:12

1 answer

2

Take a look at the Moongoose documentation . In JavaScript there is Date type. So you could build the schema as:

'use strict'

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var ReviewsSchema = Schema({
    name: String,
    date: Date,
    rating: String,
    comments: String,
    restaurantId: String
});

module.exports = mongoose.model('Reviews', ReviewsSchema);
    
03.07.2018 / 14:18