node.js - Mongoose 模式忽略值

标签 node.js mongodb azure mongoose

我要放弃了。

我有一个这样定义的架构:

var UserSchema = new Schema({
    userNick      : { type: String, required: true, index: { unique: true, sparse: true } }
  , userEmail     : { type: String, required: true, index: { unique: true, sparse: true } }
  , userPass      : { type: String, required: true }
  , userRole      : { type: String, default: 4 }
  , userFirstname : String
  , userLastname  : String
  , userImage       : String
  , userBday        : { type: Date, required: true }
  , userCreated   : { type: Date, default: Date.now }
});
var userModel = mongoose.model('UserModel', UserSchema);

我觉得没什么特别的。但是当我尝试保存新用户时, userRole 和 userBday 被忽略。 我使用输入 type=date 作为生日并按如下方式分割值:

var bdayReformat = data.BDay.split('-');
var bDay = new Date(bdayReformat[0], bdayReformat[1]-1, bdayReformat[2]);

返回:1973 年 4 月 5 日星期四 00:00:00 GMT+0100 (CEST)

我声明:

account = new userModel({
    userNick      : data.Nickname
  , userEmail     : data.Email
  , userPass      : data.Password
  , userFirstname : data.Firstname
  , userLastname  : data.Lastname
  , userImage     : 'media/noimage.png'
  , userBday      : bDay
});

然后我要保存: 这是结果:

{ userNick: 'XXXXXXX',
  userEmail: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8cd4d4d4ccd4d4d4d4d4a2e8e9" rel="noreferrer noopener nofollow">[email protected]</a>',
  userPass: 'XXXXXXX',
  userImage: 'media/noimage.png',
  _id: 50cdb5d77fbdc88013000001,
  userCreated: Sun Dec 16 2012 12:51:51 GMT+0100 (CET) }

我不知道为什么 userRole 或 bDay 没有保存。 我是服务器端编程的初学者,也是 mongodb 和 mongoose 的绝对初学者。

感谢您的帮助 我正在使用 Nodejs v0.8.15 Mongoose 3.5 使用免费的 mongolab-db 存储在 azurecloud 中

IDE(如果您有提示)是 Webstorm 5 我使用的是 MAC

最佳答案

self 回答。这是双重代码的问题。

关于node.js - Mongoose 模式忽略值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13901127/

相关文章:

python - Django mongoengine 文档中的 Manytomany 字段

MongoDB Aggregation,有没有办法从聚合游标中获取 executionStats?

azure - 逻辑应用程序是否需要集成服务环境才能与我们的 Azure 租户中的 SQL 数据库进行通信?

在 IIS Express 下运行的 Node.js 不断崩溃

node.js - 无法在 Swift 5 中调用 https 请求(自签名证书)

node.js - 将 npm 列表保存到文件

javascript - 如何在ejs标签中插入javascript变量

Swift 包管理器导致 Alamofire 产生错误

azure - 在terraform中如何根据变量将数值转换为字符串

node.js - "clean"在Sails.js 中使用不同ORM(例如node-orm2)的方法?