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

查看:23
本文介绍了是否可以在添加之前获取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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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