我有以下user文件:{ "_id":{ "$oid":"627cc1add375d47675b8104a" }, "email":"[email protected]", "username":"camille.balzac", "password":"9394516cc9354d3ef1a37a88dfefc364182a80c59a147ba77b240ac78ca5e788", "salt":"xooRCeSUh9KVmGH", "isteacher":false, "instances":[ { "instanceid":"i-0c7a14f4bebaxxxxx", "identifier":"t1u4sm2abyc3rdkhevrgs0tg5592idjp", "teacherid":{ "$oid":"627cc1a9d375d47675b81049" } }, { "instanceid":"i-0e4c61434a85xxxxx", "identifier":"pqqloehk4oeiy2ofh4d7tsn6j281wnbe", "teacherid":{ "$oid":"627cc1a9d375d47675b81049" } } ]}我正在嘗試構建一個 go 函數,該函數將刪除instances其 id 在作為參數 ( ) 傳遞的切片中的所有實體instancesIds。現在它看起來像這樣:func DeleteInstancesById(instancesIds []string) error { res, err := usersCollection.UpdateOne( context.TODO(), bson.M{}, bson.M{ "$pull": bson.M{ "instances": bson.M{ "instanceid": bson.M{ "$in": instancesIds, }, }, }, }, )}例如,這意味著如果我這樣調用函數:DeleteInstancesById([]string{"i-0c7a14f4bebaxxxxx"})它應該刪除所有 ID 為“i-0c7a14f4bebaxxxxx”的實例。問題是盡管我進行了多次嘗試,但沒有進行任何更新。任何想法 ?
- 1 回答
- 0 關注
- 90 瀏覽
添加回答
舉報
0/150
提交
取消