我试图到处寻找这个问题的答案,但似乎我不走运。
我有一个非常简单的猫鼬模型
var userObject = {
profile: {
username: {
type: String,
required: true,
lowercase: true
},
firstname: {
type: String,
required: true
},
lastname: {
type: String,
required: true
},
img: {
type: String,
required: true,
match: /^(https?:\/\/)/i
},
email: {
type: String,
match: /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/,
required: true
},
singupdate: {
type: Date,
default: Date.now
}
}
};
Run Code Online (Sandbox Code Playgroud)
而且,当我创建模式时,我选择了在添加不在模型中的属性时抛出错误的选项。
new mongoose.Schema(userObject, { strict: "throw" });
Run Code Online (Sandbox Code Playgroud)
这就是我试图捕捉错误的方式。当我添加有效属性时,该过程会运行并记录创建的文档,但是当我添加无效属性时,该过程永远不会退出,并且日志永远不会出现在控制台上。
try {
User.create(users, function(err, docs) {
console.log("err: " + err);
console.log("docs: " + docs); …Run Code Online (Sandbox Code Playgroud) 我在C#编写了一个使用日期的程序.它从SQL Server表中获取值.我使用的是Windows 7,程序运行正常.我有这行代码:
DateTime fechaOperacion = Convert.ToDateTime(reader["FechaOperacion"]);
Run Code Online (Sandbox Code Playgroud)
读者以24小时格式返回日期,我能够将其转换为DateTime变量.
现在我对Windows 10进行了系统升级,同样的代码行引发了以下错误:
字符串未被识别为有效的DateTime.从索引20开始有一个未知单词.
现在读者返回am/pm格式,而索引20则是am或pm
我试过以下的事情:
将代码行改为:
Convert.ToDateTime(reader["FechaOperacion"], System.Globalization.CultureInfo.InvariantCulture)reader.GetDateTime(reader.GetOrdinal("FechaOperacion")); 将文化转换为24小时格式
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(1033);
Run Code Online (Sandbox Code Playgroud)但这些似乎都不起作用,我不知道还能做些什么.