如何在nodejs和mongodb中发布日期对象

如何在nodejs和mongodb中发布日期对象,mongodb,mongoose,Mongodb,Mongoose,以下是我的模式定义: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var StudentSchema = new Schema({ name: String, family: String, created: { type: Date, default: Date.now} }); module.exports = mongoose.mode

以下是我的模式定义:

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

var StudentSchema   = new Schema({
    name: String,
    family: String,
    created: {
    type: Date,
    default: Date.now}
});

module.exports = mongoose.model('Student', StudentSchema);
我怎样才能把它寄出去?因为无论我发布什么值,它都是默认值,即当前时间。我尝试了以下两件事:

{
    "name": "abc",
    "family": "xyz",
    "created": "2016-12-12"
}

{
    "name": "abc",
    "family": "xyz",
    "created": "1467883104"
}

在这两种情况下,它只存储当前时间。不是我要传递的字段。

您的模式将创建的
字段定义为
日期
对象。然而,您试图存储的是一个普通字符串。你必须通过一个真正的考试:


您的模式将字段
created
定义为
Date
对象。然而,您试图存储的是一个普通字符串。你必须通过一个真正的考试:

{
    name: "abc",
    family: "xyz",
    created: new Date("2016-12-12")
}