小编jha*_*ane的帖子

如何在 Firestore 中设置外键?

例如,考虑一个电子商务应用程序,其中用户可以上传尽可能多的项目,并且这些项目具有类别和子类别。

如何在发布的每个项目中将 user_id 设置为外键,以及在用户集合中设置 item_id 以查询特定用户发布的所有项目。

我们如何利用Firestore 中的引用数据类型来设置外键?

还有其他设置外键的方法吗?

数据库结构:

Users/doc_id/name..

Categories/fashion/clothing/auto_doc_id/type:denims
Run Code Online (Sandbox Code Playgroud)

java android firebase google-cloud-firestore

10
推荐指数
1
解决办法
1万
查看次数

使用 Intent.FLAG_ACTIVITY_SINGLE_TOP 和 CLEAR_TOP 时附加功能未通过

doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if(!imgUriList.isEmpty())
            {
                    Intent intent = new Intent(getBaseContext(), createAdActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imgUriList);
                    startActivity(intent);


            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

这是我在第二个活动中使用的代码,用于将额外内容发送到第一个活动。

我想在从第二个活动回来时保持第一个活动的原样。因此我使用了_SINGLE_TOP,CLEAR_TOP FLAGS。

没有标志它工作得很好。但是使用了 extras 后 extras 就变成空了。这是我在第一个活动中使用的代码。

 @Override
    protected void onResume() {
        super.onResume();
        Toast.makeText(this,"IN RESUME ",Toast.LENGTH_LONG).show();
        imageUris = getIntent().getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if(getIntent().hasExtra(Intent.EXTRA_STREAM)) {
            if (!imageUris.isEmpty()) {
                createAdViewPagerAdapter viewpager = new createAdViewPagerAdapter(this,imageUris);
                photoViewer.setAdapter(viewpager);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

由于第一个活动还使用了从 MainActivity 发送的一些额外内容,因此我也覆盖了 onNewIntent() 方法。

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
}
Run Code Online (Sandbox Code Playgroud)

android android-intent android-activity

4
推荐指数
1
解决办法
516
查看次数

FireStore 批量写入不同的集合

是否有另一种方法可以对属于各种集合的多个文档执行一组写入?

有点像官方文档中的对多个文档进行批量写入。

FireStore 文档上的事务和批量写入

举个例子;

WriteBatch batch = db.batch();

// Set the value of 'NYC' in 'cities' collection

DocumentReference nycRef = db.collection("cities").document("NYC");
batch.set(nycRef, map1);


// Set the value of 'ABC' in 'SomeOtherCollection' collection

DocumentReference otherRef = db.collection("SomeOtherCollection").document("ABC");
batch.set(otherRef,map2));
Run Code Online (Sandbox Code Playgroud)

是否可以对不同的集合执行批量写入?

android firebase google-cloud-firestore

3
推荐指数
1
解决办法
1373
查看次数