Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 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 | |
| 7 | package driver |
| 8 | |
| 9 | import ( |
| 10 | "github.com/mongodb/mongo-go-driver/mongo/options" |
| 11 | ) |
| 12 | |
| 13 | // WriteModel is the interface satisfied by all models for bulk writes. |
| 14 | type WriteModel interface { |
| 15 | writeModel() |
| 16 | } |
| 17 | |
| 18 | // InsertOneModel is the write model for insert operations. |
| 19 | type InsertOneModel struct { |
| 20 | Document interface{} |
| 21 | } |
| 22 | |
| 23 | func (InsertOneModel) writeModel() {} |
| 24 | |
| 25 | // DeleteOneModel is the write model for delete operations. |
| 26 | type DeleteOneModel struct { |
| 27 | Filter interface{} |
| 28 | Collation *options.Collation |
| 29 | } |
| 30 | |
| 31 | func (DeleteOneModel) writeModel() {} |
| 32 | |
| 33 | // DeleteManyModel is the write model for deleteMany operations. |
| 34 | type DeleteManyModel struct { |
| 35 | Filter interface{} |
| 36 | Collation *options.Collation |
| 37 | } |
| 38 | |
| 39 | func (DeleteManyModel) writeModel() {} |
| 40 | |
| 41 | // UpdateModel contains the fields that are shared between the ReplaceOneModel, UpdateOneModel, and UpdateManyModel types |
| 42 | type UpdateModel struct { |
| 43 | Collation *options.Collation |
| 44 | Upsert bool |
| 45 | UpsertSet bool |
| 46 | } |
| 47 | |
| 48 | // ReplaceOneModel is the write model for replace operations. |
| 49 | type ReplaceOneModel struct { |
| 50 | Filter interface{} |
| 51 | Replacement interface{} |
| 52 | UpdateModel |
| 53 | } |
| 54 | |
| 55 | func (ReplaceOneModel) writeModel() {} |
| 56 | |
| 57 | // UpdateOneModel is the write model for update operations. |
| 58 | type UpdateOneModel struct { |
| 59 | Filter interface{} |
| 60 | Update interface{} |
| 61 | // default is to not send a value. for servers < 3.6, error raised if value given. for unack writes using opcodes, |
| 62 | // error raised if value given |
| 63 | ArrayFilters options.ArrayFilters |
| 64 | ArrayFiltersSet bool |
| 65 | UpdateModel |
| 66 | } |
| 67 | |
| 68 | func (UpdateOneModel) writeModel() {} |
| 69 | |
| 70 | // UpdateManyModel is the write model for updateMany operations. |
| 71 | type UpdateManyModel struct { |
| 72 | Filter interface{} |
| 73 | Update interface{} |
| 74 | // default is to not send a value. for servers < 3.6, error raised if value given. for unack writes using opcodes, |
| 75 | // error raised if value given |
| 76 | ArrayFilters options.ArrayFilters |
| 77 | ArrayFiltersSet bool |
| 78 | UpdateModel |
| 79 | } |
| 80 | |
| 81 | func (UpdateManyModel) writeModel() {} |