2016-09-25 23 views
1

我有類似...錯誤/ MGO

type Item struct { 
    Name string `json:"name" bson:"name"` 
    Config map[string]interface{} `json:"config" bson:"config,inline"` 
} 

func (repository *ItemRepository) UpdateConfig(id string, config map[string]interface{}) { 
    change := mgo.Change{ 
    Update: bson.M{"$set": bson.M{ 
     "config": config, 
    }}, 
    }, 
} 

但我得到一個錯誤Raw Unmarshal can't deal with struct values. Use a pointer.。我不完全確定這意味着什麼,或者期望的是什麼。是否可以將「鬆散」數據作爲子文檔存儲?

+0

使用'config'的指針而不是'config'本身 –

+0

仍然有同樣的錯誤@simon_xia –

回答

0

我通過使用Update而不是FindId(id).Apply(change, nil)來解決此問題。