【问题标题】:unable to select the Id in Firestore无法在 Firestore 中选择 ID
【发布时间】:2018-09-17 19:39:32
【问题描述】:

我正在使用 firestore,在用户 Employee 集合下,我想使用 id 删除特定员工。我的代码是

export const employeeSave = ({
    name,
    phone,
    shift,
    uid
}) => {
    const {
        currentUser
    } = firebase.auth();
    return (dispatch) => {
        firebase.firestore().collection('users').doc(currentUser.uid).collection('employees').doc(uid).update({
            name,
            phone,
            shift
        }).then(() => {
            dispatch({
                type: EMPLOYEE_SAVE_SUCCESS
            });
            Actions.employeeList({
                type: 'reset'
            });
        });
    };
};

【问题讨论】:

标签: javascript firebase google-cloud-firestore


【解决方案1】:

.update 需要一个对象或键/值对。所以试试:

.update({
 name: "joe",
 phone: "123-234-5567",
 shift: "night"
})

【讨论】:

  • 非常感谢您回复删除选定的员工,我正在使用此代码 export const employeeDelete = ({ uid }) => { const { currentUser } = firebase.auth(); firebase.firestore().collection('users').doc(currentUser.uid).collection('employees').doc(uid) .delete() .then(() => { Actions.employeeList({ type: '重置' }); });但它抛出错误'relativePath.split 不是函数'请帮助我
【解决方案2】:

听起来你只想调用 delete

firebase.firestore().collection('users').doc(currentUser.uid).collection('employees').doc(uid).delete()

查看更多https://firebase.google.com/docs/firestore/manage-data/delete-data

【讨论】:

  • 谢谢你的回复,我和你提到的一样,然后它抛出这个错误'relativePath.split is not a function'请帮忙
  • 您需要在 javascript 方面做得更好。这不是 Firebase 问题。
猜你喜欢
  • 2018-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-19
  • 1970-01-01
  • 1970-01-01
  • 2016-06-22
  • 1970-01-01
相关资源
最近更新 更多