Я пытаюсь получить объект коллекции Mongo. Я не хочу использовать модель, потому что мои поля не зафиксированы в коллекции Mongo.
Здесь мои customer_ref
и _id
являются фиксированными полями, а другие поля - нет. Возможно, что поля добавлены или удалены.
Как получить доступ к полям $ref
и $id
, которые являются ссылками на другие коллекции?
{
"_id" : "SQ74P",
"_class" : "com.vo.License",
"vendor" : "te",
"product" : "ty",
"product_id" : "7.4",
"version" : "17.0",
"is_deleted" : false,
"customer_ref" : {
"$ref" : "customer",
"$id" : "IG_7.4"
}
}
Я пробовал это:
Контроллер:
@RestController
@EnableAutoConfiguration
@RequestMapping("/license/demo")
public class DemoLiController {
@Autowired
DemoLicRepository demoLicRepository;
@RequestMapping(value = "/lic", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Object>> findLicense() throws Exception {
Map<String, Object> test = demoLicRepository.findbylic("SIT1");
return new ResponseEntity<Map<String, Object>>(test, HttpStatus.OK);
}
Repository:
@Repository
public class DemoLicRepository {
@Autowired
MongoTemplate template;
public Map<String, Object> findbylicenseid(String key) throws Exception {
Query findQuery = new Query();
findQuery.addCriteria(Criteria.where("_id").is(key));
template.findOne(findQuery, Map.class, "win_lic");
Map<String, Object> res = template.findOne(findQuery, Map.class, "win_licenses_poc");
return template.findOne(findQuery, Map.class, "win_licenses_poc")
}
Если я удаляю блок customer_ref
, код работает нормально.