Skip to content

Commit 2fe0393

Browse files
committed
feat: Added PrepareFindOneAndUpdateOptions function
1 parent 0a7bab6 commit 2fe0393

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

mongodb/options.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,32 @@ func PrepareUpdateOptions(upsert bool) *options.UpdateOptions {
6060

6161
return updateOptions
6262
}
63+
64+
// PrepareFindOneAndUpdateOptions prepares the find one and update options
65+
func PrepareFindOneAndUpdateOptions(
66+
projection interface{},
67+
sort interface{},
68+
upsert bool,
69+
returnDocument options.ReturnDocument,
70+
) *options.FindOneAndUpdateOptions {
71+
// Create the find one and update options
72+
findOneAndUpdateOptions := options.FindOneAndUpdate()
73+
74+
// Set the projection
75+
if projection != nil {
76+
findOneAndUpdateOptions.SetProjection(projection)
77+
}
78+
79+
// Set the sort
80+
if sort != nil {
81+
findOneAndUpdateOptions.SetSort(sort)
82+
}
83+
84+
// Set the upsert
85+
findOneAndUpdateOptions.SetUpsert(upsert)
86+
87+
// Set the return document
88+
findOneAndUpdateOptions.SetReturnDocument(returnDocument)
89+
90+
return findOneAndUpdateOptions
91+
}

0 commit comments

Comments
 (0)