【发布时间】:2022-01-16 01:00:37
【问题描述】:
如果在给定坐标内不存在其他文档,我将使用此库 https://geofirestore.com/ 在集合中创建文档。现在,我应该在 Cloud 函数中还是直接在应用程序中使用这个库的方法进行交易?
我个人认为没有理由在云端执行此操作,但我可能错了,所以我征求您的意见。
const geocollection = GeoFirestore.collection('chats');
const query = geocollection.limit(1).near({ center: new firebase.firestore.GeoPoint(latitude, longitude), radius: 0.03 });
GeoFirestore.runTransaction((transaction) => {
const geotransaction = new GeoTransaction(transaction);
return geotransaction.get(query).then((sfDoc) => {
if (sfDoc.exists) {
sfDoc.docs.forEach(documentSnapshot => {
if (documentSnapshot.exists) {
firestore().collection('chats')
.doc(documentSnapshot.id)
.get()
.then((res) => {
// insert new document
geocollection.add({
name: 'Geofirestore',
uid: device_id,
coordinates: new firebase.firestore.GeoPoint(latitude, longitude),
created: currenttime
})
})
}
});
} else {
geocollection.add({
name: 'Geofirestore',
uid: device_id,
coordinates: new firebase.firestore.GeoPoint(latitude, longitude),
created: currenttime
})
}
});
});
【问题讨论】:
标签: javascript react-native google-cloud-firestore google-cloud-functions geofirestore