Docs Menu
Docs Home
/ / /
Go 드라이버
/ /

문서 삭제

DeleteOne() 메서드를 사용하여 collection에서 문서를 삭제할 수 있습니다.

이 예제를 실행하는 방법을 알아보려면 사용 예제 를 읽어보세요.

다음 예시에서는 title이 'Twilight'인 movies 컬렉션의 문서를 매칭하여 일치하는 첫 번째 문서를 삭제합니다.

coll := client.Database("sample_mflix").Collection("movies")
filter := bson.D{{"title", "Twilight"}}
// Deletes the first document that has a "title" value of "Twilight"
result, err := coll.DeleteOne(context.TODO(), filter)
// Prints a message if any errors occur during the operation
if err != nil {
panic(err)
}

완전히 실행 가능한 예시를 확인합니다.

전체 예시를 실행하면 movies 컬렉션에서 다음 문서가 제거됩니다.

// result truncated
{ "_id": ObjectId("..."), ..., "title": "Twilight", ... }

문서를 찾는 방법에 대한 예는 문서 찾기를 참조하세요.

문서 삭제에 대한 자세한 내용은 문서 삭제를 참조하세요.

DeleteOne()

돌아가기

문서 교체하기