Я пытаюсь получить все документы, которые соответствуют приведенным ниже критериям, но результат кажется неверным.
Критерии: фильмы, дата выпуска которых соответствует заданному диапазону, и эта временная шкала выпуска активна
isActive = true и releaseDate> = 2020-04-20 и releaseDate <= 2020-04-21 </p>
Каждый документ имеет тип Mov ie, который содержит список movieTimeline У каждого объекта movieTimeline есть свойство isActive и releaseDate. В любой момент в фильме может быть активен отдельный movieTimeline.
Структура документа -
@Document
public class Movie extends BaseDocument
{
private String name;
private List<MovieTimeline> movieTimelines;
...
public class MovieTimeline
{
private Boolean isActive;
private LocalDateTime releaseDate;
private String description;
...
Свойство даты выпуска имеет тип LocalDateTime в Java и хранится в 2020-04-20T05: 00: Формат 00.000 + 00: 00 в БД.
Это код, который я пытался извлечь из данных -
@Repository
public interface MovieRepository extends MongoRepository<Movie,String>
{
List<Movie> findByMovieTimelines_ReleaseDateBetweenAndMovieTimelines_IsActive(LocalDateTime from, LocalDateTime to, boolean isActive);
}
Пример данных -
{
"id": "abc",
"name": "Rango",
"movieTimelines": [{
"isActive": false,
"releaseDate": "2020-02-10T11:30:00",
"description": "ORIGINAL TIMELINE"
}, {
"isActive": true,
"releaseDate": "2020-06-15T10:30:00",
"description": "New Timeline created on 03/10/2020"
}
]
}, {
"id": "abcv",
"name": "Fight Club",
"movieTimelines": [{
"isActive": false,
"releaseDate": "2020-02-10T11:30:00",
"description": "ORIGINAL TIMELINE"
}, {
"isActive": true,
"releaseDate": "2020-05-18T10:30:00",
"description": "New Timeline created on 02/05/2020"
}
]
}, {
"id": "asd",
"name": "Death Note",
"movieTimelines": [{
"isActive": false,
"releaseDate": "2020-03-09T10:30:00",
"description": "ORIGINAL TIMELINE"
}, {
"isActive": false,
"releaseDate": "2020-03-16T10:30:00",
"description": "New Timeline created on 02/05/2020"
}, {
"isActive": false,
"releaseDate": "2020-04-20T10:30:00",
"description": "New Timeline created on 03/06/2020"
}, {
"isActive": true,
"releaseDate": "2020-04-20T10:30:00",
"description": "New Timeline created on 03/06/2020"
}
]
}, {
"id": "gfj",
"name": "Andhadhun",
"movieTimelines": [{
"isActive": false,
"releaseDate": "2020-04-13T10:30:00",
"description": "ORIGINAL TIMELINE"
}, {
"isActive": true,
"releaseDate": "2020-07-20T10:30:00",
"description": "New Timeline created on 03/09/2020"
}
]
}, {
"id": "nojh",
"name": "Evan Almighty",
"movieTimelines": [{
"isActive": true,
"releaseDate": "2020-04-20T10:30:00",
"description": "ORIGINAL TIMELINE"
}
]
}
Ожидается-
{
"id": "asd",
"name": "Death Note",
"movieTimelines": [{
"isActive": false,
"releaseDate": "2020-03-09T10:30:00",
"description": "ORIGINAL TIMELINE"
}, {
"isActive": false,
"releaseDate": "2020-03-16T10:30:00",
"description": "New Timeline created on 02/05/2020"
}, {
"isActive": false,
"releaseDate": "2020-04-20T10:30:00",
"description": "New Timeline created on 03/06/2020"
}, {
"isActive": true,
"releaseDate": "2020-04-20T10:30:00",
"description": "New Timeline created on 03/06/2020"
}
]
},{
"id": "nojh",
"name": "Evan Almighty",
"movieTimelines": [{
"isActive": true,
"releaseDate": "2020-04-20T10:30:00",
"description": "ORIGINAL TIMELINE"
}
]
}
Есть ли в MongoDB какие-либо фильтры или операторы, которые можно использовать для извлечения этих документов в одном запросе?