小编czp*_*lip的帖子

如何在本地测试`functions.https.onCall` firebase云功能?

我在Firebase文档中找不到解决方案.

我想在functions.https.onCall本地测试我的功能.是否可以使用shell或以某种方式将我的客户端(启用firebase SDK)连接到本地服务器?

我想避免每次只是为了测试对我的onCall功能的更改而进行部署.


我的代码

功能:

exports.myFunction = functions.https.onCall((data, context) => {
  // Do something
});
Run Code Online (Sandbox Code Playgroud)

客户:

const message = { message: 'Hello.' };

firebase.functions().httpsCallable('myFunction')(message)
  .then(result => {
    // Do something //
  })
  .catch(error => {
    // Error handler //
  });
Run Code Online (Sandbox Code Playgroud)

firebase google-cloud-functions

11
推荐指数
4
解决办法
6014
查看次数

如何在react-native中添加新的构建env变量(例如staging)?

我知道在react-native中我们可以__DEV__用来确定我们是在运行调试版本还是发布版本.

staging在Xcode中创建了一个新的构建配置(用于测试版),并希望在js代码中检测这个env.我怎样才能做到这一点?

目标是让我的应用程序连接到debug构建中的localhost api,构建中的dev api和staging构建中的生产api release.

xcode react-native

5
推荐指数
1
解决办法
358
查看次数

Firestore 数据建模和查询类似 Tinder 的应用程序

为了让事情更简单,假设应用程序只有 2 个实体:theuser和 the post,它们是用户创建的内容。

用户可以做三件事:

  1. 创建帖子
  2. 在帖子上滑动,喜欢或不喜欢
  3. 取消关注帖子的作者,以便他/她不再看到作者的帖子

我的问题是:如何posts根据作者是否被我取消关注来查询?

我对数据建模的第一种方法

users/{userId}
- userId

posts/{postId}
- author <userId>
- content

unfollows/{userId}
- userId
- unfollowedUserId

likes/{postId_userId}
- postId
- userId

dislikes/{postId_userId}
- postId
- userId
Run Code Online (Sandbox Code Playgroud)

查询帖子:

// get all userIds that I unfollow

const unfollows = collection('unfollows').where('userId', '==', 'myUserId');
Run Code Online (Sandbox Code Playgroud)

但是后来我不知道如何有效地posts使用unfollows用户 id 数组进行查询。

// This doesn't seem correct and
// I don't know how to write the `where` filters programmatically:

// assume …
Run Code Online (Sandbox Code Playgroud)

data-modeling nosql firebase google-cloud-firestore

5
推荐指数
0
解决办法
732
查看次数

Firestore 规则 - 仅允许更新文档的某些字段

我的目标

我只想允许用户更新其他人的用户文档中的特定字段。


我的用户文档

/* BEFORE */
{
  id: 'uid1',
  profile: { /* a map of personal info */ },
  connectedUsers: {
    uid2: true,
    uid3: true,
  }
}

/* AFTER */
{
  id: 'uid1',
  profile: { /* a map of personal info */ },
  connectedUsers: {
    uid2: true,
    uid3: true,
    uid4: true, // <--- added.
  }
}
Run Code Online (Sandbox Code Playgroud)

请求

const selfUserId = 'uid4';

db.runTransaction(function(transaction) {

    return transaction.update(userDocRef).then(function(userDoc) {

        if (!userDoc.exists) { throw "Document does not exist!"; }

        transaction.update(userDocRef, 'connectedUsers.${selfUserId}', true);
    });
} …
Run Code Online (Sandbox Code Playgroud)

firebase-security google-cloud-firestore

5
推荐指数
1
解决办法
2093
查看次数