我只想为每个运行 Cloud Functions 的实例连接一次 Atlas 集群。
这是我的实例代码:
const MongoClient = require("mongodb").MongoClient;
const client = new MongoClient("myUrl", {
useNewUrlParser: true,
useUnifiedTopology: true,
});
exports.myHttpMethod = functions.region("europe-west1").runWith({
memory: "128MB",
timeoutSeconds: 20,
}).https.onCall((data, context) => {
console.log("Data is: ", data);
client.connect(() => {
const testCollection = client.db("myDB").collection("test");
testCollection.insertOne(data);
});
});
Run Code Online (Sandbox Code Playgroud)
我想避免client.connect()在每个函数调用中看起来确实太多了。
我想做这样的事情:
const MongoClient = require("mongodb").MongoClient;
const client = await MongoClient.connect("myUrl", {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const db = client.db("myDB");
exports.myHttpMethod = functions.region("europe-west1").runWith({
memory: "128MB",
timeoutSeconds: 20,
}).https.onCall((data, context) => …Run Code Online (Sandbox Code Playgroud) mongodb node.js firebase google-cloud-platform google-cloud-functions
我在遵循此处使用 count() 聚合的示例时遇到错误
我的代码是:
const collectionRef = db.collection('cities');
const snapshot = await collectionRef.count().get();
const amount = snapshot.data().count;
res.json({ amount });
Run Code Online (Sandbox Code Playgroud)
错误说:
函数:类型错误:collectionRef.count不是函数
有人可以帮忙吗?
有没有一种方法可以创建自定义索赔而无需通过云功能?
我真的只需要为几个帐户设置它,我目前的计划是 Spark。我现在还不能升级。但我需要测试此功能以实现基于角色的身份验证。
谢谢,请尽可能详细,因为我是 firebase cli 的新手。
firebase firebase-authentication google-cloud-functions firebase-admin
这里的官方片段说:
// You can access the new user via result.user
// Additional user info profile not available via:
// result.additionalUserInfo.profile == null
// You can check if the user is new or existing:
// result.additionalUserInfo.isNewUser
Run Code Online (Sandbox Code Playgroud)
甚至API 参考也说:
包含因成功登录、链接或重新身份验证操作而产生的其他用户信息的对象。
不过我明白了additionalUserInfo is undefined。我需要检测电子邮件链接登录是否是新用户。
我的代码:
await setPersistence(auth, browserLocalPersistence);
const result = await signInWithEmailLink(auth, email.value, window.location.href);
if (result && result.user) {
window.localStorage.removeItem('email');
window.localStorage.removeItem('its');
console.log(result.additionalUserInfo.isNewUser()); // undefined
return router.push({ path: "/dashboard" });
}
Run Code Online (Sandbox Code Playgroud) 这是我第一次在 StackOverflow 上提问。我正在制作一个学校项目,并且我是 Firebase 和 JavaScript 的初学者。我正在尝试克隆 Tinder。React 告诉我这部分代码有错误。起初我遇到了不同的错误,但它们与 Firebase 语法相关,我立即修复了它们,但现在我不知道这个错误的含义。我的代码在本地主机上运行了一瞬间(我看到了我的应用程序),然后出现错误。
import React, { useEffect, useState } from 'react';
import TinderCard from 'react-tinder-card';
import database from './firebase';
import './SwipeCards.css';
...
function SwipeCards() {
...
useEffect(() => {
database.collection('buddies').onSnapshot((snapshot) => setBuddies(snapshot.docs.map((doc) => doc.data())));
}, []);
...
}
Run Code Online (Sandbox Code Playgroud)
我尝试了其他人遇到的类似问题的两种解决方案,即:(在我的tinderCards.js中)
database.firestore().collection('buddies')...
Run Code Online (Sandbox Code Playgroud)
和(在我的 firebase.js 中)
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
...
const firebaseApp = initializeApp(firebaseConfig);
const database = getFirestore(firebaseApp);
export default database;
Run Code Online (Sandbox Code Playgroud)
但两者都不起作用。如果需要,我可以发布更多代码。任何帮助将不胜感激。
如何使用 Firebase 函数在 Firebase 存储上上传包含 JSON 的新文件?到目前为止我的代码:
exports.scheduledFunctionCrontab = functions.pubsub.schedule("0 0 * * *")
.onRun(async () => {
try {
const response = await axios.get("api.com");
const bucket = await admin.storage().bucket();
// What now?
} catch (e) {
functions.logger.error(e);
}
return null;
})
Run Code Online (Sandbox Code Playgroud) node.js firebase google-cloud-platform google-cloud-functions firebase-storage
我有一个 Nestjs 数据库模块,它工作得很好
@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: () => {
return {
name: 'default', // <=== here
type: "mysql",
...
};
},
}),
TypeOrmModule.forFeature(entities, 'default'), // <=== here
],
exports: [TypeOrmModule],
})
export class DBModule {}
Run Code Online (Sandbox Code Playgroud)
如果我将连接名称更改为其他名称而不是“默认”、“测试”,则会收到错误
@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: () => {
return {
name: 'test', // <=== here
type: "mysql",
...
};
},
}),
TypeOrmModule.forFeature(entities, 'test'), // <=== here
],
exports: [TypeOrmModule],
})
export class DBModule {}
Run Code Online (Sandbox Code Playgroud)
[Nest] 10746 - 05/15/2021, 5:55:34 PM [ExceptionHandler] Nest …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Android 应用程序,我正在尝试将我的数据上传到firebase 实时 数据库,但它没有显示在那里,一切都设置正确,所有依赖项都设置正确,应用程序工作正常,没有错误!. 但问题是数据没有更新到实时数据库中。
buttonC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
myRef.setValue("Hello, World!");
}
});
Run Code Online (Sandbox Code Playgroud) 我写了以下代码:
def check_token(token):
response = requests.get("https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com")
key_list = response.json()
decoded_token = jwt.decode(token, key=key_list, algorithms=["RS256"])
print(f"Decoded token : {decoded_token}")
Run Code Online (Sandbox Code Playgroud)
我正在尝试解码tokenfirebase 客户端提供的内容以在服务器端验证它。
上面的代码抛出以下异常:
TypeError: Expecting a PEM-formatted key.
Run Code Online (Sandbox Code Playgroud)
我试图不将列表传递给该jwt.decode方法,只传递关键内容,并且我有一个比库更大的错误could not deserialize the Key。
我正在关注这个答案,但我收到了这个错误。
是requests转换问题吗?我究竟做错了什么 ?
我正在尝试通过电子邮件链接登录用户。
用户第二次使用该链接时出现此错误:
auth/invalid-action-code:如果操作代码无效,则抛出该异常。如果代码格式错误、过期或已被使用,则可能会发生这种情况。
我知道代码没有格式错误,因为它第一次就可以工作。因此该代码可能已过期或已被使用。但是,我不希望代码永远过期或具有最大使用次数(用户应该能够根据需要多次使用它)。
我能做些什么?