向 Firebase 规则添加索引
Adding index to Firebase rules
我正在使用 GeoFire 根据用户的当前位置从 Firebase 查询数据。我得到:
Using an unspecified index. Consider adding ".indexOn": "g" at / to
your security rules for better performance
在控制台中。下面是我的查询代码:
ref = Database.database().reference()
let geoFire = GeoFire(firebaseRef: ref)
let center = CLLocation(latitude: (userLocation.coordinate.latitude), longitude: (userLocation.coordinate.longitude))
let circleQuery = geoFire?.query(at: center, withRadius: 1)
circleQuery?.observe(.keyEntered, with: { key, location in
guard let key = key else { return }
geoFire?.getLocationForKey(key, withCallback: { (location, error) in
let myAnnotation: MKPointAnnotation = MKPointAnnotation()
myAnnotation.coordinate = CLLocationCoordinate2DMake((location?.coordinate.latitude)!, (location?.coordinate.longitude)!);
self.currentLocationMapView.addAnnotation(myAnnotation)
})
self.ref.child("services").child(key).observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? NSDictionary
let servicename = value?["name"] as? String ?? ""
let address = value?["address"] as? String ?? ""
self.nameArray.append(servicename)
self.addressArray.append(address)
if (self.nameArray.count > 0) {
self.customTableView.reloadData();
}
})
})
我的 Firebase 规则选项卡具有以下设置。
"rules": {
".read": true,
".write": "auth != null"
}
无论我在哪里插入“.indexOn”:"g",我都会出错并且无法保存规则。有帮助吗?
documentation points you to examples.
"rules": {
".read": true,
".write": "auth != null",
".indexOn": ["g"]
}
我正在使用 GeoFire 根据用户的当前位置从 Firebase 查询数据。我得到:
Using an unspecified index. Consider adding ".indexOn": "g" at / to your security rules for better performance
在控制台中。下面是我的查询代码:
ref = Database.database().reference()
let geoFire = GeoFire(firebaseRef: ref)
let center = CLLocation(latitude: (userLocation.coordinate.latitude), longitude: (userLocation.coordinate.longitude))
let circleQuery = geoFire?.query(at: center, withRadius: 1)
circleQuery?.observe(.keyEntered, with: { key, location in
guard let key = key else { return }
geoFire?.getLocationForKey(key, withCallback: { (location, error) in
let myAnnotation: MKPointAnnotation = MKPointAnnotation()
myAnnotation.coordinate = CLLocationCoordinate2DMake((location?.coordinate.latitude)!, (location?.coordinate.longitude)!);
self.currentLocationMapView.addAnnotation(myAnnotation)
})
self.ref.child("services").child(key).observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? NSDictionary
let servicename = value?["name"] as? String ?? ""
let address = value?["address"] as? String ?? ""
self.nameArray.append(servicename)
self.addressArray.append(address)
if (self.nameArray.count > 0) {
self.customTableView.reloadData();
}
})
})
我的 Firebase 规则选项卡具有以下设置。
"rules": {
".read": true,
".write": "auth != null"
}
无论我在哪里插入“.indexOn”:"g",我都会出错并且无法保存规则。有帮助吗?
documentation points you to examples.
"rules": {
".read": true,
".write": "auth != null",
".indexOn": ["g"]
}