【发布时间】:2020-05-21 13:53:16
【问题描述】:
我知道可以对具有空值的字段执行空查询。
就我而言,我有包含 Map 的文档,我想查询所有这些不包含给定键的文档。在我的例子中,这个键是一个字符串格式的日期。
我确实尝试使用以下代码执行此操作,但它不起作用。相反,它获取所有文档:
Stream<List<Employee>> availableEmployeesForGivenDesignation(
String designation, DateTime date) {
// in firstore the keys of a map are Strings, thus I have to change DateTime to String
var formatter = new DateFormat('yyyy-MM-dd');
String formatedDate = formatter.format(date);
//todo check why I am getting with null also the false employees
return _employeeCollection
.where('designations', arrayContains: designation)
.where('busy_map.$formatedDate', isEqualTo: null)
.snapshots()
.map((snapshot) {
return snapshot.documents
.map((doc) => Employee.fromEntity(EmployeeEntity.fromSnapshot(doc)))
.toList();
});
}
据我了解,我查询的是地图键,对于某些文档,此键(日期)并不总是存在。这就是为什么我试图获取这些在这种情况下返回 null 的文档。
数据库结构:
【问题讨论】:
标签: flutter google-cloud-firestore