如何在Cloud Firestore中自动生成文档ID?

时间:2019-04-26 04:18:57

标签: android firebase google-cloud-firestore

我要获取自动生成的文档ID

  

我如何获得这些自动生成的ID?

https://i.stack.imgur.com/tgui0.png

2 个答案:

答案 0 :(得分:0)

您可以使用for i in {1..7}; do echo "The count for $(date --date="$i days ago") is $(zcat "position.log.$i.gz" | wc -l)" done 对象的DataReference.push()方法来实现。

您可以查看here以获得更多信息。

答案 1 :(得分:0)

您可以尝试以下方法:-

FirebaseFirestore db = FirebaseFirestore.getInstance();
        db.collection("MartWayDB")
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        if (task.isSuccessful()) {
                            for (QueryDocumentSnapshot document : task.getResult()) {
                                String id = document.getId();
                                //or you can store these id in array list
                            }
                        } else {
                            Toast.makeText(MainActivity.this, "Error getting documents."+task.getException(), Toast.LENGTH_SHORT).show();
                        }
                    }
                });

或者您可以点击此链接:

https://firebase.google.com/docs/firestore/quickstart?authuser=0

相关问题