【问题标题】:how to write a query in firestore to update data according to id in the inner array?如何在firestore中编写查询以根据内部数组中的id更新数据?
【发布时间】:2023-03-30 03:28:01
【问题描述】:

如何访问另一个数组中的数组中的映射的id? 我在这里附上了火库结构 db structure in firestore

【问题讨论】:

  • 你可以使用Products.0.sub_products.0.city

标签: firebase google-cloud-firestore


【解决方案1】:

在你成功的firestore请求监听器中,你可以得到这样的数组!

List<String> group = (List<String>) document.get("arrayfieldname");

【讨论】:

  • 我需要知道如何使用 where() 来更新特定的数组,例如:collection.where("id","==",123).update({name:xyz})跨度>
  • 因为答案有点长,让我发布答案而不是评论。
【解决方案2】:

这是我的代码.. 我在这里使用了两个 where 条件,如您所见,您必须转到该集合的引用并添加 .where("fieldnameinfirestore", "yourvalue")..

     private void GetCityListsnames() {

    db.collection("citylist").document("city").
            collection(uservolcity).whereEqualTo("complete","false").
       whereEqualTo("takebyvol","false")
            .get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (task.isSuccessful()) {
                        for (QueryDocumentSnapshot document : task.getResult()) {

                            mlistsproper.add(new VolListProperDataModel(document.getId(),document.getString("listname"),
                                    document.getString("sendinguserphone"),
                                    document.getString("sendingusername"),
                                    document.getString("deliveryaddress"),uservolcity));

                        }
                        if(mlistsproper.size() == 0){
                            nolist.setVisibility(View.VISIBLE);
                        }
                        progressBar.setVisibility(View.INVISIBLE);
                        mAdapter.notifyDataSetChanged();
                        GetAccptListsnames();

                    } else {
                        Log.d("Errorgeetingaddres", "Error getting documents: ", task.getException());
                        Toast.makeText(getActivity().getApplicationContext(),
                                "Make sure you have added delivery address", Toast.LENGTH_SHORT).show();

                    }
                }
            });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    相关资源
    最近更新 更多