如何在猫鼬中结合两个模型属性生成唯一的密钥哈希

时间:2019-09-12 22:44:38

标签: javascript node.js mongodb mongoose

我正在尝试结合两个模型属性来生成hash

我有这样的架构

const BlogPost = new Schema({
  id: { type: String, required: true, unique: true },
  empid: String,
  date: Date
}); 

我想创建一个唯一的id,它是组合hash的{​​{1}}。如果生成相同的empid and date,则会hash错误。 我们可以结合gives生成unique吗?

如果我们通过empid and date,会产生相同的哈希吗?那给我错误

这是我的代码 https://codesandbox.io/s/lively-tree-hd0fo

empid and date

1 个答案:

答案 0 :(得分:0)

我以前使用过uuid库。 Node还具有内置的md5 hash library

相关问题