1// Copyright (C) MongoDB, Inc. 2017-present. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); you may 4// not use this file except in compliance with the License. You may obtain 5// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 6 7package driver 8 9import ( 10 "context" 11 12 "go.mongodb.org/mongo-driver/bson" 13 "go.mongodb.org/mongo-driver/x/mongo/driver/session" 14 "go.mongodb.org/mongo-driver/x/mongo/driver/topology" 15 "go.mongodb.org/mongo-driver/x/mongo/driver/uuid" 16 "go.mongodb.org/mongo-driver/x/network/command" 17 "go.mongodb.org/mongo-driver/x/network/description" 18) 19 20// DropCollection handles the full cycle dispatch and execution of a dropCollection 21// command against the provided topology. 22func DropCollection( 23 ctx context.Context, 24 cmd command.DropCollection, 25 topo *topology.Topology, 26 selector description.ServerSelector, 27 clientID uuid.UUID, 28 pool *session.Pool, 29) (bson.Raw, error) { 30 31 ss, err := topo.SelectServer(ctx, selector) 32 if err != nil { 33 return nil, err 34 } 35 36 conn, err := ss.Connection(ctx) 37 if err != nil { 38 return nil, err 39 } 40 defer conn.Close() 41 42 // If no explicit session and deployment supports sessions, start implicit session. 43 if cmd.Session == nil && topo.SupportsSessions() { 44 cmd.Session, err = session.NewClientSession(pool, clientID, session.Implicit) 45 if err != nil { 46 return nil, err 47 } 48 defer cmd.Session.EndSession() 49 } 50 51 return cmd.RoundTrip(ctx, ss.Description(), conn) 52} 53