There is a classic POJO object, as shown below:
@Document
public class MyPojo {
@DBRef
@Field("otherPojo")
private List<OtherPojo> otherPojos;
}
And OtherPojo.java:
public class OtherPojo{
@Id
private ObjectId _id;
private String someOtherFields;
}
I cannot cascade - save them, but I go to it, first saving DBRefs and then saving the POJO list, but still when I try to get the whole list or request some of them using the code below:
Query query = new Query( Criteria.where( "myPojo.blabla" ).is( "blabla" ) );
List<MyPojo> resultList = mongoTemplate.find( query, MyPojo.class, "myCollection" );
it returns me with a list of null DBrefs, it considers true. For example: 10 DBRefs are stored, it returns 10 null objects in it, but its primitive types and other types that are not DBRref are not null. How can I handle this?
I save my objects as shown below:
for (MyPojo pojo : somePojoList) {
for (OtherPojo otherPojo : pojo.getOtherPojos()) {
mongoTemplate.save(otherPojo, "myCollection");
}
}
mongoTemplate.insert( myPojoList, "myCollection" );
: , , , otherPojos, ( @jmen7070). myCollection , . . , " DBRefs"?