A K A K - 2 years ago 81
Javascript Question

Query list based on input list value

I stored data in mongoDB in User Collection in below format

"_id" : ObjectId("571ded1a1b8bd2c34aaf3c4a"),
"_class" : "com.unisys.workbench.domain.User",
"userName" : "admin",
"password" : "admin",
"email" : "xyzq@gmail.com",
"contact1" : "9889482416",
"contact2" : "1234567890",
"roles" : [
"roleName" : "ROLE_ADMIN"

To Restive data based on roleName I written Below Query

List<User> users= mongoTemplate.find(new Query().addCriteria(Criteria.where("roles.$roleName").is(role)),

But its always returning null .

For email below Query is working fine

mongoTemplate.findOne(new Query().addCriteria(Criteria.where("email").is(email)),

Answer Source

What is the $ for? It should be:

List<User> users= mongoTemplate.find(new Query().addCriteria(Criteria.where("roles.roleName").is(role)),
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download