How do you declare date on Node Express?

Asked

Viewed 34 times

1

I’m with 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 am declaring the date attribute right, if it is not right how I should declare the date attribute?

I am using Node Express with Mongodb.

NOTE: in the Front-End application I will need to use pipe to convert the date, that’s why I’m asking, because I think declaring date as String is not right.

  • 1

    There is a "date" data type in Mongoose. http://mongoosejs.com/docs/schematypes.html

1 answer

2

Take a look at moongoose documentation. In Javascript there is the type Date. Soon, you could build the scheme 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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.