2 回答

TA貢獻(xiàn)1802條經(jīng)驗 獲得超5個贊
解決了:
我使用以下代碼解決了這個錯誤:
var jsonDocuments []map[string]interface{}
var byteDocuments []byte
var bsonDocument bson.D
var jsonDocument map[string]interface{}
var temporaryBytes []byte
for cursor.Next(context.Background()) {
err = cursor.Decode(&bsonDocument)
...
temporaryBytes, err = bson.MarshalExtJSON(bsonDocument, true, true)
...
err = json.Unmarshal(temporaryBytes, &jsonDocument)
...
jsonDocuments = append(jsonDocuments, jsonDocument)
}

TA貢獻(xiàn)1827條經(jīng)驗 獲得超4個贊
temp := itemBson.data.(primitive.D) // convert interface to primitive D
metadata := temp.Map() // map to map[string]interface{}
if v, ok := metadata[prqKey]; ok { // check and use value
commitID = v.(string)
}
您可以使用類型的內(nèi)置接口primitive.D將其轉(zhuǎn)換為map[string]interface{}
- 2 回答
- 0 關(guān)注
- 246 瀏覽
添加回答
舉報