I have following documents in my mongodb:
{
"_id" : ObjectId("64cc954d8e68f438ca3c44b0"),
"empId" : "EMP-30066",
"empName" : "Alex_Mortin",
"dept" : {
"name" : "CE"
},
"country" : {
"name" : "US"
},
"qualifications" : [ ],
"_class" : "ama.me.model.backend.Employee"
},
{
"_id" : ObjectId("64cc954d8e68f438ca3c44a8"),
"empId" : "EMP-30077",
"empName" : "Luisa_Deo",
"dept" : {
"name" : "DG"
},
"country" : {
"name" : "US"
},
"qualifications" : [ ],
"_class" : "ama.me.model.backend.Employee"
},
I want to add a validation in my Spring Boot application before POST and PUT request to make sure in every object empId, empName, dept, country will be unique. qualifications will be ignored for validation check.
I have already got the desired result using the following query:
db.empLists.countDocuments({
"empId" : "EMP-30066",
"empName" : "Alex_Mortin",
"dept" : {
"name" : "CE"
},
"country" : {
"name" : "US"
}
},{limit: 1})
But, I need this in mongoTemplate which I am using in my Spring Boot application.