我們如何將原始 M 轉換為字符串?package mainimport ( "go.mongodb.org/mongo-driver/bson")func main() { a := bson.M{ // primitive.M "test": bson.M{ "fielda": "AAA", "fieldb": "BBB", }, }}我正在使用它來記錄進程中失敗的 mongodb 文檔。我能夠使用 打印值logrus.Error,我想將此轉換復制為字符串,然后將其記錄到文件中。// cursor = "go.mongodb.org/mongo-driver/mongo" *mongo.Cursor// logrus = "github.com/sirupsen/logrus"//... var temp bson.M _ := cursor.Decode(&temp) // assume this is not returning error, it will log the map logrus.Error("value: ", temp) // value: map[__v:0 _id:ObjectID(\"5c8ef7df7216e9935ecd7859\") field1:test]
如何將primitive.M轉換為映射[字符串]字符串然后轉換為字符串?
慕婉清6462132
2022-06-27 15:08:31