首页 > 解决方案 > 我如何获得 blogpostId 火库?

问题描述

我的问题是从 Firestore 获取文档 ID。

我如何获取 Users/documentid/Comments/documentid ?

数据类:

public class BlogPostId {


  @Exclude
  public String BlogPostId;

  public <T extends BlogPostId> T withId(@NonNull final String id) {
    this.BlogPostId = id;
    return (T) this;
  }
}

添加活动:

private String blog_post_id;

Oncreate
blog_post_id = getIntent().getStringExtra("blog_post_id");

btn click
final String descff = icerikedit.getText().toString();

Map<String, Object> commentsMap = new HashMap<>();
            commentsMap.put("descff", descff);
            commentsMap.put("user_id", current_user_id);
            commentsMap.put("timestamp", FieldValue.serverTimestamp());

            firebaseFirestore.collection("Users/"+blog_post_id+"/Comments").add(commentsMap).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
    @Override
    public void onComplete(@NonNull Task<DocumentReference> task) {


        if(task.isSuccessful()){

            Toast.makeText(FFicerikAdd.this, "Başarılı efe!", Toast.LENGTH_SHORT).show();

            Intent sab=new Intent(getApplicationContext(),FFicerik.class);
            sab.putExtra("blog_post_id",blog_post_id);

            startActivity(sab);

        }

标签: javaandroidfirebasegoogle-cloud-firestore

解决方案


不幸的是,Cloud Firestore 无法在单个查询中获取文档中存在的名称和文档中Mehmet存在的名称。zSNQ...mUUFahmetSinifDevam

Firestore 中的查询很浅,它们仅从运行查询的集合中获取项目。无法从单个查询中的另一个顶级集合和/或子集合中获取文档。Firestore 不支持一步跨不同集合的查询。单个查询只能使用单个集合中的文档属性

为了解决这个问题,您应该在一个集合中添加所有用户对象并相应地查询它。


推荐阅读