【发布时间】:2022-01-05 13:54:58
【问题描述】:
我想在 MongoDB 中创建一个模式,我可以在其中将时区保存到 MongoDB 数据库中。 我有这个作为架构
'use strict';
var mongoose = require('mongoose'),
bcrypt = require('bcrypt'),
Schema = mongoose.Schema;
var UserSchema = new Schema({
fullname :{
type:String,
trim:true,
required:true
},
email:{
type:String,
unique:true,
lowercase:true,
trim:true,
required:true
},
hash_password:{
type:String
},
timezone:{
type:String,
},
created:{
type: Date,
default: Date.now
}
});
UserSchema.methods.comparePassword = function(password){
return bcrypt.compareSync(password,this.hash_password);
};
mongoose.model('User', UserSchema);
假设我想将时区保存在数据库中。我如何将它也包含在架构中?我只是将其保存为纯字符串吗?或者究竟是什么?
【问题讨论】:
-
您确定需要吗?在许多情况下,存储没有时区的时间戳并将其强制为 Zulu 时间会使事情变得更简单,因为您可以使用一个时间来进行比较和执行定期操作。