是否可以在添加ID之前获取ID? [英] Is It Possible To Get The ID Before It Was Added?

查看:68
本文介绍了是否可以在添加ID之前获取ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Realtime Database中我可以像这样添加push ID之前得到它:

I know that in Realtime Database I could get the push ID before it was added like this:

 DatabaseReference databaseReference= FirebaseDatabase.getInstance().getReference();
 String challengeId=databaseReference.push().getKey();

,然后可以使用此ID添加它.

and then I could add it using this ID.

我也可以在Cloud Firestore?

推荐答案

文档.请参阅添加文档"部分的最后一段.

This is covered in the documentation. See the last paragraph of the add a document section.

DocumentReference ref = db.collection("my_collection").doc();
String myId = ref.id;

这篇关于是否可以在添加ID之前获取ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆