[英]How to send non-persistent value to Cloud Firestore?
I want to send some value for a field
to Cloud Firestore
, but I dont want to be persist(saved)
in Cloud Firestore
.我想将某个
value for a field
发送到Cloud Firestore
,但我不想在Cloud Firestore
中persist(saved)
。
Code:代码:
const message = {
persistentData: {
id: 'dSXYdieiwoDUEUWOssd',
text: 'Hi dear how are you',
date: new Date();
},
nonPersistentData: {
securityCode: 393929949
}
};
db.collection('messages').doc(message.persistentData.id).set(message).catch(e => {});
In above code I want to persit (save)
persistentData
, but I dont want to save
nonPersistentData
online nor offline
, because I only need them to check real data in Firestore rule
.在上面的代码中,我想
persit (save)
persistentData
,但我不想online nor offline
save
nonPersistentData
,因为我只需要它们检查Firestore rule
中的真实数据。 So I dont want they should be accessible
in cache(offline) or server(online)
...所以我不希望它们
accessible
在cache(offline) or server(online)
中访问...
This is simply not possible with firestore.这对于 Firestore 来说根本不可能。 There is a similar question here .
这里有一个类似的问题。 You need to separate the data into public (persistent) and private data (non-persistent).
您需要将数据分为公共(持久)和私有数据(非持久)。 One possible solution will be-
一种可能的解决方案是 -
match /securityCodes/{securityCode} {
// No one can read the value from this collection, but only create
allow create: true;
}
data = {
id: 'dSXYdieiwoDUEUWOssd',
text: 'Hi dear how are you',
date: new Date(),
securityId: <id of the secretCode entry>
}
match /collectionId/documentId {
allow create: if get(/secretCodes/$(request.resource.data.secretId)) == 'someknowncode'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.