Привет, я получаю данные о человеке на основе атрибутов, которые присутствуют в атрибутах "Атрибуты карты = new LinkedHashMap ();
с помощью Query mongoTemplate Creteria. и вот мой код
на основе атрибутов любой пары ключ и значение мне нужно получить подробную информацию о классе сущности Documents. используя post man
это мой класс POJO / сущности
@Document(collection = "document")
public class Documents {
@Id
private String _id;
@Field(value = "username")
private String username;
@Field(value = "userrole")
private String userrole;
@Field(value = "attributes")
Map<String, Object> attributes = new LinkedHashMap<>();
/**
* @return the attributes
*/
public Map<String, Object> getAttributes() {
return attributes;
}
@JsonAnySetter
public void setAttributes(String key, Object value) {
this.attributes.put(key, value);
}
this is my DAO/Repository interface
public interface Repository{
List<Documents> findByAttributes(Map<String, Object> attributes);
}
this is my service implementation class
@Autowired
public DatabaseServiceImpl(MongoTemplate mongoTemplate) {
this.mongoTemplate = mongoTemplate;
}
@Override
public List<Documents> findByAttributes(Map<String, Object> attributes) {
Query query = new Query();
query.addCriteria(Criteria.where("attributes").is(attributes));
return mongoTemplate.find(query, Documents.class);
}
and controller class
@requestMapping("/files")
class controlle{
@GetMapping("/nr")
public List<Documents> getByAttributes(@RequestParam Map<String, Object> attributes) {
logger.info("get Attribute controller" + attributes);
return dataService.findByAttributes(attributes);
}
}
значение хранится в mongodb в следующем формате
"_id": "5d1b2c3a774818444c9e7356",
"documentTypeGroup": null,
"attributes": {
"name": "ayush",
"vin": "hello",
"sss": "1234",
"appid": "1234abcd"