Javascript firestore集合中的promise参数未定义
我正在尝试创建一个新文档,然后使用以下方式在承诺内执行某些操作:Javascript firestore集合中的promise参数未定义,javascript,promise,google-cloud-firestore,Javascript,Promise,Google Cloud Firestore,我正在尝试创建一个新文档,然后使用以下方式在承诺内执行某些操作: firestore.collection('users').doc(uid).set({name: "testName"}) .then(res => { console.log("set data correctly with ", res); }).catch(err => { console.log('something went wrong '
firestore.collection('users').doc(uid).set({name: "testName"})
.then(res => {
console.log("set data correctly with ", res);
}).catch(err => {
console.log('something went wrong '+ err)
});
它确实进入了然后的承诺。但是,res
是空的!
我得到:
使用“未定义”正确设置数据
返回一个
承诺
。因此,预计不会有任何值传递给then()。
请查看API文档以了解。方法的定义如下:
set(data: DocumentData, options?: SetOptions): Promise<void>
set(数据:DocumentData,options?:SetOptions):承诺
请注意,该方法返回一个包含void
的承诺。这意味着set()根本不会生成任何对象或数据
因此,如果你履行承诺,它将一无所获。因此,它的工作正如预期的那样。下面回答为什么会发生这种情况。您试图在
then()
回调中执行什么操作,您需要什么值?