javascript - 如何在猫鼬中结合两个模型属性生成唯一的密钥哈希
问题描述
我正在尝试生成hash
两个模型属性的组合。
我有这样的架构
const BlogPost = new Schema({
id: { type: String, required: true, unique: true },
empid: String,
date: Date
});
我想创建一个独特id
的hash
组合 。如果生成empid and date
相同的话,我会出错。我们可以组合生成吗?hash
gives
unique
empid and date
如果我们通过,将生成相同的哈希empid and date
?然后它给了我错误
这是我的代码 https://codesandbox.io/s/lively-tree-hd0fo
try {
var blog = new BlogPostModel({
empid: "test123",
date: "19-Jul-2019"
});
console.log("before save");
let saveBlog = await blog.save(); //when fail its goes to catch
console.log(saveBlog); //when success it print.
console.log("saveBlog save");
} catch (error) {
console.log(error);
}
解决方案
推荐阅读
- ansible - 在剧本结束时打印出主机失败的任务?
- python - 蟒蛇 | 如何捕获文件不可读的异常
- php - 如何检查选择标签是否选择了一些值并获取值以通过 PHPMailer 发送?
- javascript - 我无法使用 FormGroup Angular 6 发出发布请求
- css - Bootstrap-4.3 中的多图像滑动轮播问题
- groovy - 有没有一种干净的方法可以在 Groovy 中指定 Closure 参数类型?
- php - PHP 创建租约计算器
- javascript - 如何阻止视图占用屏幕宽度并与 React Native 中的其他组件重叠?
- c# - 在 C# 插件中使用 ChromiumFX/ChromiumWebBrowser
- python - Bloomberg API 如何仅获取用户在 Python 中指定的给定时间的最新报价?