【问题标题】:Want to delete a set of data from firestore in my ionic 4 project想在我的 ionic 4 项目中从 firestore 中删除一组数据
【发布时间】:2019-12-12 02:58:42
【问题描述】:

我能够从 Firestore 上传和获取数据,但问题是删除收集的数据。下面是我的代码 我的服务

        delete_AcBooking(record_id) {
   return this.afirestore.doc(`users/${this.user.getUID()}/AcBooking` + record_id).delete();
}

组件.ts

    RemoveRecord(rowID) {
  this.bookingservice.delete_AcBooking(rowID);
}

错误

ERROR FirebaseError: Invalid document reference. Document references must have an even number of segments, but users/pht1VUEXbFfkD3udB9Q3cMwWtcH2/AcBookingLHF9Yj9JkoFpaUOsJtpd has 3
at new FirestoreError (http://localhost:4200/vendor.js:85176:28)
at Function.push../node_modules/@firebase/firestore/dist/index.cjs.js.DocumentReference.forPath (http://localhost:4200/vendor.js:105305:19)
at Firestore.push../node_modules/@firebase/firestore/dist/index.cjs.js.Firestore.doc (http://localhost:4200/vendor.js:105091:34)
at AngularFirestore.push../node_modules/@angular/fire/firestore/firestore.js.AngularFirestore.doc (http://localhost:4200/vendor.js:67496:34)
at BookingServiceService.push../src/app/service/booking-service.service.ts.BookingServiceService.delete_AcBooking (http://localhost:4200/main.js:5076:25)
at BookingsPage.push../src/app/pages/bookings/bookings.page.ts.BookingsPage.RemoveRecord (http://localhost:4200/pages-bookings-bookings-module.js:333:29)
at Object.eval [as handleEvent] (ng:///BookingsPageModule/BookingsPage.ngfactory.js:44:31)
at handleEvent (http://localhost:4200/vendor.js:65419:41)
at callWithDebugContext (http://localhost:4200/vendor.js:66489:25)
at Object.debugHandleEvent [as handleEvent] (http://localhost:4200/vendor.js:66216:12)

【问题讨论】:

  • 旁注:您是否阅读过有关删除的文档?删除数据集有许多复杂性,不建议在客户端执行此操作。 docs

标签: angular typescript node-modules ionic4


【解决方案1】:

您似乎缺少一些/。请尝试以下操作:

this.afirestore.doc(`users/${this.user.getUID()}/AcBooking/${record_id}`).delete();

或者做:

return this.afirestore
  .collection('users')
  .doc(this.user.getUID())
  .collection('AcBooking')
  .doc(record_id)
  .delete()

这里我假设AcBooking 是一个集合。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-08
    • 2021-08-14
    • 2021-04-03
    • 2019-10-03
    • 2019-11-08
    • 1970-01-01
    • 2020-03-14
    • 2021-06-11
    相关资源
    最近更新 更多