小编Jak*_*ake的帖子

删除Firestore集合中的所有文档

我正在寻找清除整个收藏夹的方法。我看到有一个批处理更新选项,但这需要我知道集合中的所有文档ID。

我正在寻找一种简单地删除集合中每个文档的方法。

谢谢!

编辑:下面的答案是正确的,我使用以下方法:

  func delete(collection: CollectionReference, batchSize: Int = 100) {
// Limit query to avoid out-of-memory errors on large collections.
// When deleting a collection guaranteed to fit in memory, batching can be avoided entirely.
collection.limit(to: batchSize).getDocuments { (docset, error) in
  // An error occurred.
  let docset = docset

  let batch = collection.firestore.batch()
  docset?.documents.forEach { batch.deleteDocument($0.reference) }

  batch.commit {_ in
    self.delete(collection: collection, batchSize: batchSize)
  }
}
Run Code Online (Sandbox Code Playgroud)

}

swift google-cloud-firestore

11
推荐指数
6
解决办法
1万
查看次数

如何限制API调用的数量?

我有一个阅读条形码的应用程序.如果检测到条形码,它将使用API​​获取有关检测到的元数据的信息.问题是,在每次扫描时,它实际上读取条码30-40次,这可能是一个问题,因为我每小时只允许进行1000次API调用.

有一种简单的方法可以在处理扫描或API调用时"暂停"扫描或API调用吗?

override func viewDidLoad() {
    super.viewDidLoad()

  // Get an instance of the AVCaptureDevice class to initialize a device object and provide the video as the media type parameter.
  let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)

  let yellow1 = UIColor(red: 0.427, green: 0.429, blue: 0.144, alpha: 1.0)

  do {
    // Get an instance of the AVCaptureDeviceInput class using the previous device object.
    let input = try AVCaptureDeviceInput(device: captureDevice)

    // Initialize the captureSession object.
    captureSession = AVCaptureSession()

    // Set the input device on …
Run Code Online (Sandbox Code Playgroud)

ios swift swift3

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

标签 统计

swift ×2

google-cloud-firestore ×1

ios ×1

swift3 ×1