如何将用户输入的数据与我的 Firestore 记录进行比较。

huangapple go评论71阅读模式
英文:

how to compare user input data with my firestore record

问题

我想将用户的输入数据与我的Firestore记录进行比较(这些数据已经存储在我的Firebase中)。

Task<QuerySnapshot> pLJava = CoRef
            .whereEqualTo("ProgrammingLanguages", "Java")
            .get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (task.isSuccessful()) {
                        for (QueryDocumentSnapshot document : task.getResult()) {
                            // document.getData();
                            id = document.getId();
                            if (id.contains("Java")) {

                            }
                        }
                    }
                }
            });

我已经编写了一个算法来查询输入数据。现在我想将输入数据与我的Firebase记录进行比较。

感谢您提供的所有帮助!

英文:

I want to compare the input data of a user, with my firestore record (data that is already stored in my Firebase.

Task&lt;QuerySnapshot&gt; pLJava = CoRef
            .whereEqualTo(&quot;ProgrammingLanguages&quot;, &quot;Java&quot;)
            .get()
            .addOnCompleteListener(new OnCompleteListener&lt;QuerySnapshot&gt;() {
                @Override
                public void onComplete(@NonNull Task&lt;QuerySnapshot&gt; task) {
                    if (task.isSuccessful()) {
                        for (QueryDocumentSnapshot document : task.getResult()) {
                            // document.getData();
                            id = document.getId();
                            if (id.contains(&quot;Java&quot;)) {

                            }

I already wrote an algorithm to query the input data. Now I want to compare the input data with my Firebase record.

Thanks for all the help in forward!

答案1

得分: 0

直接将文档转换为POJO。Firestore API中有一个名为toObject(Class<T> valueType)的方法用于解决此问题。

YourClass foo = document.toObject(YourClass.class);

然后,您可以将对象数据与用户输入数据进行比较。

英文:

Simply convert the document into a POJO. There's a method toObject(Class&lt;T&gt; valueType) in Firestore API which resolves that.

YourClass foo = document.toObject(YourClass.class);

Then, you may compare the object data with the user's input data.

huangapple
  • 本文由 发表于 2020年5月4日 17:12:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/61588740.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定