Android 如何根据firestore中的hashmap值筛选项目

Android 如何根据firestore中的hashmap值筛选项目,android,firebase,google-cloud-firestore,Android,Firebase,Google Cloud Firestore,我的结构如下: 这里,“subjects”是一个hashmap数组 现在,我想在我的集合中找到id=1的所有文档 学生收藏班: String name; String div; String phoneNumber; ArrayList<SubjectInStudentModel> subjects=new ArrayList<>(); int id; ArrayList<String> dates=new

我的结构如下:

这里,“subjects”是一个hashmap数组

现在,我想在我的集合中找到id=1的所有文档

学生收藏班:

    String name;
    String div;
    String phoneNumber;
    ArrayList<SubjectInStudentModel> subjects=new ArrayList<>();
    int id;
    ArrayList<String> dates=new ArrayList<String>();
当hashmap中没有“日期”时,这种方法有效

类似地,以下代码在日期为空时工作

SubjectInStudentModel subjectInStudentModel = new SubjectInStudentModel();
subjectInStudentModel.setDates(new ArrayList<String>());
subjectInStudentModel.setId(subjectId);
db.collection("student").whereArrayContains("subjects", subjectInStudentModel).get()
subjectionstudentmodel subjectionstudentmodel=new subjectionstudentmodel();
setDates(新的ArrayList());
subjectionStudentModel.setId(subjectId);
db.collection(“学生”).whererraycontains(“主题”,subjectionstudentmodel).get()

arrayContains操作符检查数组中是否已经存在整个对象,因此ID和日期都存在。它不能只检查该对象的一个属性

要使当前检查生效,您需要传入一个包含主题所有数据的对象


或者,您可以创建一个附加字段,仅保留每个主题的ID(例如,
subjectID
),然后在该字段上使用
arrayContains

到目前为止您尝试了什么?@AlexMamo我更新了问题,添加了有关结构和我尝试的内容的更多信息。我尝试了类似的方法,Map test=newhashmap();测试。放置(“id”,主体);db.collection(“student”).whererraycontains(“subjects”,test)。get()它对我有用。
SubjectInStudentModel subjectInStudentModel = new SubjectInStudentModel();
subjectInStudentModel.setDates(new ArrayList<String>());
subjectInStudentModel.setId(subjectId);
db.collection("student").whereArrayContains("subjects", subjectInStudentModel).get()