With Spring-Data, you can use the @Document annotation to indicate which collection to save the object. Say I have two classes: Student and Teacher, both stored in a collection of people. When I execute the following code:
mongo.find(new Query(), Teacher.class);
The result contains both the student and the teacher. In the data created by Spring -Data, each document contains a "_class" field, which indicates which class it is stored from.
Is this a field that is not used in the search as a filter to return only Teachers? How can I request only Teacher, except for this:
mongo.find(new Query().addCriteria(where("_class").is(Teacher.class.getCanonicalName()), Teacher.class);
, . Mongo , , . , . , _class DefaultMongoTypeMapper.DEFAULT_TYPE_KEY.
_class
DefaultMongoTypeMapper.DEFAULT_TYPE_KEY
API , , , :
mongo.find(new Query(Teacher.class), Teacher.class);
- , ( , , ). , , , , . Person , , , .
Person
, ( , Object, ), , . @Document.
Object
@Document
: , JIRA, , .
:
query.restrict(Teacher.class,Teacher.class);