Skip to content

Commit

Permalink
Merge pull request #6 from idealo/random_updating_test
Browse files Browse the repository at this point in the history
fix: take random docid for update test
  • Loading branch information
manuelkasiske4idealo authored Nov 8, 2024
2 parents 94a604a + 9a8a19f commit 3b1376d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ func main() {
defer wg.Done()
threadDocCount := docCount / threads
for j := 0; j < threadDocCount; j++ {
docID := int64(threadID*threadDocCount + j)

switch testType {
case "insert":
docID := int64(threadID*threadDocCount + j)
doc := bson.M{
"_id": docID,
"threadId": threadID,
Expand All @@ -106,6 +105,8 @@ func main() {
}

case "update":
// Choose a random document ID within the range of `docCount`
docID := int64(rand.Intn(docCount))
filter := bson.M{"_id": docID}
update := bson.M{"$set": bson.M{"updatedAt": time.Now().Unix(), "rnd": rand.Int63()}}
_, err := collection.UpdateOne(context.Background(), filter, update)
Expand Down

0 comments on commit 3b1376d

Please sign in to comment.