blob: d317bb7fabff29742a18f19d952dad6b513f605a [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
7// Package result contains the results from various operations.
8package result
9
10import (
11 "time"
12
13 "github.com/mongodb/mongo-go-driver/bson"
14 "github.com/mongodb/mongo-go-driver/bson/primitive"
15 "github.com/mongodb/mongo-go-driver/x/bsonx"
16)
17
18// Upsert contains the information for a single upsert.
19type Upsert struct {
20 Index int64 `bson:"index"`
21 ID interface{} `bson:"_id"`
22}
23
24// Insert is a result from an Insert command.
25type Insert struct {
26 N int
27 WriteErrors []WriteError `bson:"writeErrors"`
28 WriteConcernError *WriteConcernError `bson:"writeConcernError"`
29}
30
31// StartSession is a result from a StartSession command.
32type StartSession struct {
33 ID bsonx.Doc `bson:"id"`
34}
35
36// EndSessions is a result from an EndSessions command.
37type EndSessions struct{}
38
39// Delete is a result from a Delete command.
40type Delete struct {
41 N int
42 WriteErrors []WriteError `bson:"writeErrors"`
43 WriteConcernError *WriteConcernError `bson:"writeConcernError"`
44}
45
46// Update is a result of an Update command.
47type Update struct {
48 MatchedCount int64 `bson:"n"`
49 ModifiedCount int64 `bson:"nModified"`
50 Upserted []Upsert `bson:"upserted"`
51 WriteErrors []WriteError `bson:"writeErrors"`
52 WriteConcernError *WriteConcernError `bson:"writeConcernError"`
53}
54
55// Distinct is a result from a Distinct command.
56type Distinct struct {
57 Values []interface{}
58}
59
60// FindAndModify is a result from a findAndModify command.
61type FindAndModify struct {
62 Value bson.Raw
63 LastErrorObject struct {
64 UpdatedExisting bool
65 Upserted interface{}
66 }
67}
68
69// WriteError is an error from a write operation that is not a write concern
70// error.
71type WriteError struct {
72 Index int
73 Code int
74 ErrMsg string
75}
76
77// WriteConcernError is an error related to a write concern.
78type WriteConcernError struct {
79 Code int
80 ErrMsg string
81 ErrInfo bson.Raw
82}
83
84// ListDatabases is the result from a listDatabases command.
85type ListDatabases struct {
86 Databases []struct {
87 Name string
88 SizeOnDisk int64 `bson:"sizeOnDisk"`
89 Empty bool
90 }
91 TotalSize int64 `bson:"totalSize"`
92}
93
94// IsMaster is a result of an IsMaster command.
95type IsMaster struct {
96 Arbiters []string `bson:"arbiters,omitempty"`
97 ArbiterOnly bool `bson:"arbiterOnly,omitempty"`
98 ClusterTime bson.Raw `bson:"$clusterTime,omitempty"`
99 Compression []string `bson:"compression,omitempty"`
100 ElectionID primitive.ObjectID `bson:"electionId,omitempty"`
101 Hidden bool `bson:"hidden,omitempty"`
102 Hosts []string `bson:"hosts,omitempty"`
103 IsMaster bool `bson:"ismaster,omitempty"`
104 IsReplicaSet bool `bson:"isreplicaset,omitempty"`
105 LastWriteTimestamp time.Time `bson:"lastWriteDate,omitempty"`
106 LogicalSessionTimeoutMinutes uint32 `bson:"logicalSessionTimeoutMinutes,omitempty"`
107 MaxBSONObjectSize uint32 `bson:"maxBsonObjectSize,omitempty"`
108 MaxMessageSizeBytes uint32 `bson:"maxMessageSizeBytes,omitempty"`
109 MaxWriteBatchSize uint32 `bson:"maxWriteBatchSize,omitempty"`
110 Me string `bson:"me,omitempty"`
111 MaxWireVersion int32 `bson:"maxWireVersion,omitempty"`
112 MinWireVersion int32 `bson:"minWireVersion,omitempty"`
113 Msg string `bson:"msg,omitempty"`
114 OK int32 `bson:"ok"`
115 Passives []string `bson:"passives,omitempty"`
116 ReadOnly bool `bson:"readOnly,omitempty"`
117 SaslSupportedMechs []string `bson:"saslSupportedMechs,omitempty"`
118 Secondary bool `bson:"secondary,omitempty"`
119 SetName string `bson:"setName,omitempty"`
120 SetVersion uint32 `bson:"setVersion,omitempty"`
121 Tags map[string]string `bson:"tags,omitempty"`
122}
123
124// BuildInfo is a result of a BuildInfo command.
125type BuildInfo struct {
126 OK bool `bson:"ok"`
127 GitVersion string `bson:"gitVersion,omitempty"`
128 Version string `bson:"version,omitempty"`
129 VersionArray []uint8 `bson:"versionArray,omitempty"`
130}
131
132// IsZero returns true if the BuildInfo is the zero value.
133func (bi BuildInfo) IsZero() bool {
134 if !bi.OK && bi.GitVersion == "" && bi.Version == "" && bi.VersionArray == nil {
135 return true
136 }
137
138 return false
139}
140
141// GetLastError is a result of a GetLastError command.
142type GetLastError struct {
143 ConnectionID uint32 `bson:"connectionId"`
144}
145
146// KillCursors is a result of a KillCursors command.
147type KillCursors struct {
148 CursorsKilled []int64 `bson:"cursorsKilled"`
149 CursorsNotFound []int64 `bson:"cursorsNotFound"`
150 CursorsAlive []int64 `bson:"cursorsAlive"`
151}
152
153// CreateIndexes is a result of a CreateIndexes command.
154type CreateIndexes struct {
155 CreatedCollectionAutomatically bool `bson:"createdCollectionAutomatically"`
156 IndexesBefore int `bson:"numIndexesBefore"`
157 IndexesAfter int `bson:"numIndexesAfter"`
158}
159
160// TransactionResult holds the result of committing or aborting a transaction.
161type TransactionResult struct {
162 WriteConcernError *WriteConcernError `bson:"writeConcernError"`
163}
164
165// BulkWrite holds the result of a bulk write operation.
166type BulkWrite struct {
167 InsertedCount int64
168 MatchedCount int64
169 ModifiedCount int64
170 DeletedCount int64
171 UpsertedCount int64
172 UpsertedIDs map[int64]interface{}
173}