2017-10-13 12 views
0

私はそれらが何であるかを知っているが、私は少し例えば、セキュリティルールについて混乱しています意味:Firestoreのルール、コレクションとドキュメントは何ですか?

service cloud.firestore { 
    match /databases/{database}/documents { 
    // This is probably a mistake 
    match /spaceships { // <= what is this a collection or a document? 
     allow read; 
     // In spite of the above line, a user can't read any document within the 
     // spaceship collection. 
    } 
    } 
} 

Firebaseドキュメントは言う:コレクションの

ルール内のドキュメントには適用されません。そのコレクション。ドキュメントレベルではなくコレクションレベルで書かれたセキュリティルールを持つことは珍しいことです(おそらくエラーです)。

つまり、match /spaceships {...はコレクション権利ですか?

service cloud.firestore { 
    match /databases/{database}/documents { 
    match /{document=**}{ // <= what is this a document or a collection? 
     allow read, write: if true; 
    } 
    } 
} 

私は理解していないが、このmatch /{document=**}{...文書です:

しかし、その後の

我々はこれを持っていますか?またはコレクション?私はコレクションレベルにあることを意味します。 Firestoreで

答えて

1

パスは、コレクションや文書を交互にされています/collection/document/subcollection/subdocument

をたとえば:

// Matches kaylee, the mechanic on serenity 
/spaceships/serenity/crew/kaylee/... 

セキュリティルールを使用する場合は、ワイルドカードを指定することができます。

// This will match any spaceship, and any crewmember 
/spaceships/{spaceshipId}/crew/{crewmemberId}/... 

今あなたが持っていることを想像します別のサブコレクション:spaceships

あなたが複数のサブコレクションに対してルールを記述する場合
/spaceships/{spaceshipId}/stowaways/{stowawayId}/... 

、あなたはどちらかを行う必要があります。

// You could use multiple single wildcards 
/spaceships/{spaceshipId}/{crewOrStowaway}/{crewOrStowawayId}/... 

// Or you could use a multi-segment wildcard 
/spaceships/{spaceshipId}/{allShipInformation=**} 

これは、そのパスで上下にすべての文書コレクションにマッチするパスとしてallShipInformationを返します。 0以上ではなく、1つ以上のパスセグメントであることに注意してください。

あなたはあなたの最初の例では/spaceshipsこのin the docs

0

詳細を読むことができ、コレクションレベルです。参照した見積もりに記載されているように、ここにルールを置くことは、コレクション内のどのドキュメントにも適用されないため、役立たない。

/{document=**}はコレクションレベルですが、recursive wildcardを使用しています。簡単に言えば、これはルールをこのコレクション内の文書とこのコレクションのサブコレクション内の文書に適用することです。

service cloud.firestore { 
    match /databases/{database}/documents { 
    match /{document=**}{ 
     allow read, write: if true; 
    } 
    } 
} 

の代わりに::

service cloud.firestore { 
    match /databases/{database}/documents { 
    match /spaceships/{shipId} { 
     allow read, write: if true; 
    } 
    match /spaceships/{shipId}/crew/{crewMemberId} { 
     allow read, write: if true; 
    } 
    } 
} 

これは、あなたが書くことができます

関連する問題