I have a calendar schema that has the date field:
const mongoose = require('../config/db');
const AgendaSchema = new mongoose.Schema({
nome: {
type: String,
require: true
},
local: {
type: String,
require: true
},
data: {
type: Date,
default: Date.now,
require: true
},
createdAt: {
type: Date,
default: Date.now
}
});
const Agenda = mongoose.model('Agenda', AgendaSchema);
module.exports = Agenda;
But the mongoose when saving the date is saving with the date from the previous day. Detail in the Date.now field saves the correct date.
Form:
<form class="form-horizontal" action="/admin/agenda-create/" method="post">
<div class="form-group row">
<label class="col-sm-3 form-control-label">Nome</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="nome" id="nome" >
</div>
</div>
<div class="line"></div>
<div class="form-group row">
<label class="col-sm-3 form-control-label">Local</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="local" id="local">
</div>
</div>
<div class="line"></div>
<div class="form-group row">
<label class="col-sm-3 form-control-label">Data</label>
<div class="col-sm-9">
<input type="date" class="form-control" name="data" id="data" >
</div>
</div>
<div class="line"></div>
<div class="form-group row">
<div class="col-sm-4 offset-sm-3">
<button type="submit" class="btn btn-secondary">Cancelar</button>
<button type="submit" class="btn btn-primary">Salvar</button>
</div>
</div>
</form>