1 Attachment(s)
Support of MongoDB update $pull operation with expressions
Hi all,
I was wondering if the Update pull method supports expressions of the type
Code:
{ $pull : { field : {field2: value} } } removes array elements with field2 matching value
Code:
{ $pull : { field : {$gt: 3} } } removes array elements greater than 3
Code:
{ $pull : { field : {<match-criteria>} } } removes array elements meeting match criteria
In particular my case is as follows:
Code:
public void removeByOfficeAndLastUpdatedDate(Long officeOid, Collection<Long> departureOids, Date olderThan) {
Update cabinFareUpd = new Update();
WriteResult updateResult = this.mongoTemplate.updateMulti(
query(where(BaseFareFields.OFFICE_OID.getValue()).is(officeOid).
and(BaseFareFields.DEPARTURE_OID.getValue()).in(departureOids).
and(BaseFareFields.CABIN_FARE.getValue()).elemMatch(where(BaseFareFields.LAST_UPDATED_DATE.getValue()).lte(olderThan))),
cabinFareUpd.pull(BaseFareFields.LAST_UPDATED_DATE.getValue(),
query(where(BaseFareFields.LAST_UPDATED_DATE.getValue()).lte(olderThan))), BaseFare.class);
logger.info(updateResult.toString());
}
Basically I want to remove an array element within a document whose last udpated date is less that the informed date.
The execution of the pull method as written above currently throws an exception:
Code:
java.lang.StackOverflowError
at java.util.HashMap$EntryIterator.<init>(Unknown Source)
at java.util.HashMap$EntryIterator.<init>(Unknown Source)
at java.util.HashMap.newEntryIterator(Unknown Source)
at java.util.HashMap$EntrySet.iterator(Unknown Source)
at java.util.AbstractMap.hashCode(Unknown Source)
at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:336)
at org.springframework.data.util.TypeDiscoverer.hashCode(TypeDiscoverer.java:365)
at org.springframework.data.util.ClassTypeInformation.hashCode(ClassTypeInformation.java:39)
at java.util.concurrent.ConcurrentHashMap.hash(Unknown Source)
at java.util.concurrent.ConcurrentHashMap.get(Unknown Source)
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:151)
...
I have attached the complete stack trace here Attachment 5205
Thanks in advance for your help,
Sebastian