I am trying to generate hash
in a combination of two model attribute.
I have schema like this
const BlogPost = new Schema({
id: { type: String, required: true, unique: true },
empid: String,
date: Date
});
I want to create a unique id
which is hash
of the combination empid and date
.if same hash
is generated it gives
me error.
can we generate unique
in a combination of empid and date
?
Same hash will be generated if we pass empid and date
? then it gives me error
here is my code 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);
}