2017-10-05 93 views
7

新的火力地堡數據庫公司的FireStore說嵌套數組不支持

功能DocumentReference.set()調用無效數據。嵌套數組不支持。

當試圖保存下列對象:

{ 
    "desc" : "Blala", 
    "geojson" : { 
    "features" : [ { 
     "geometry" : { 
     "coordinates" : [ 8.177433013916017, 48.27753810094064 ], 
     "type" : "Point" 
     }, 
     "type" : "Feature" 
    } ], 
    "type" : "FeatureCollection" 
    }, 
    "location" : { 
    "lat" : 48.27753810094064, 
    "lng" : 8.177433013916017 
    }, 
    "name" : "Wald und Wiesen", 
    "owner" : "8a2QQeTG2zRawZJA3tr1oyOAOSF3", 
    "prices" : { 
    "game" : { 
     "Damwild" : 10, 
     "Raubwild" : 300, 
     "Rehwild" : 250, 
     "Schwarzwild" : 40 
    }, 
    "perDay" : 35 
    }, 
    "rules" : "Keine Regeln!", 
    "wild" : { 
    "desc" : "kein Wild", 
    "tags" : [ "Damwild", "Rehwild", "Schwarzwild", "Raubwild" ] 
    } 
} 

究竟是嵌套數組公司的FireStore抱怨?我無法在文檔中找到它。

如果是GeoJSON對象 - 我將如何保存它?

+0

有趣的是,這個文件建議支持嵌套數組。也許這是代碼或文檔中的錯誤? https://cloud.google.com/firestore/docs/manage-data/add-data#data_types –

回答

5

這是當前發佈的SDK中的一個錯誤。

後端有限制,只有直接嵌套的數組不受支持。

在你的情況下,你有包含數組的對象的數組,當客戶端不應該驗證邏輯時,客戶端的驗證邏輯是不允許的。

有沒有公開的錯誤跟蹤這個,但我會回來,當我們有一個修復。

+0

非常感謝 – ProblemsOfSumit

2

您可以修改序列化函數,將數組與對象類型轉換爲映射。鑰匙可以是數字來維持秩序。

{ 1: Object, 2: Object2 ... }

在反序列化,你可以得到Object.values(data);把它恢復到一個數組中使用的客戶端。