blob: 574d0275e2c6d5c06fa76bfef522fd16168f9ebc [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// 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 "github.com/mongodb/mongo-go-driver/x/mongo/driver/topology"
13 "github.com/mongodb/mongo-go-driver/x/network/command"
14 "github.com/mongodb/mongo-go-driver/x/network/description"
15 "github.com/mongodb/mongo-go-driver/x/network/result"
16)
17
18// KillCursors handles the full cycle dispatch and execution of an aggregate command against the provided
19// topology.
20func KillCursors(
21 ctx context.Context,
22 cmd command.KillCursors,
23 topo *topology.Topology,
24 selector description.ServerSelector,
25) (result.KillCursors, error) {
26 ss, err := topo.SelectServer(ctx, selector)
27 if err != nil {
28 return result.KillCursors{}, err
29 }
30 desc := ss.Description()
31 conn, err := ss.Connection(ctx)
32 if err != nil {
33 return result.KillCursors{}, err
34 }
35 defer conn.Close()
36 return cmd.RoundTrip(ctx, desc, conn)
37}