@Id字段注释用于将POJO存储在Firebase Firestore中? [英] @Id field annotation for storing POJO in Firebase Firestore?

查看:40
本文介绍了@Id字段注释用于将POJO存储在Firebase Firestore中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个复杂的JSON,该JSON在主对象内部具有多个子对象.例如:

We have a complex JSON having multiple sub-objects inside main object. For example:

dept: {
   name: Dept1,
   emps: [
     {
        empCode: 001,
        empName: Emp001
     }
   ]
}

如果我们使用 db.collection("dept").add(deptPojo),则它会自动创建"emps"子集合并为每个emp对象自动分配文档ID.但是我们希望将empCode分配为每个emp文档的文档ID.这是可以实现的吗?如何?Firebase Firestore API中是否有任何@Id注释?

If we use db.collection("dept").add(deptPojo) then it auto creates "emps" subcollection and auto assigns document id for each emp object. But we want empCode to be assigned as document id for each emp document. Is this achievable? How? Is there any @Id annotation in firebase firestore api?

推荐答案

已更新
现在您可以使用firebase中的 @DocumentId 进行操作.只需将其添加到POJO类中即可.

Updated
Now you can do it using @DocumentId from firebase.Just add it in your POJO class

这篇关于@Id字段注释用于将POJO存储在Firebase Firestore中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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