...
1
2
3
4
5
6
7 package unified
8
9 import (
10 "context"
11 "fmt"
12
13 "go.mongodb.org/mongo-driver/bson"
14 )
15
16 func executeIterateOnce(ctx context.Context, operation *operation) (*operationResult, error) {
17 cursor, err := entities(ctx).cursor(operation.Object)
18 if err != nil {
19 return nil, err
20 }
21
22
23 if cursor.TryNext(ctx) {
24
25
26 var res bson.Raw
27 if err := cursor.Decode(&res); err != nil {
28 return nil, fmt.Errorf("error decoding cursor result: %w", err)
29 }
30
31 return newDocumentResult(res, nil), nil
32 }
33 return newErrorResult(cursor.Err()), nil
34 }
35
36 func executeIterateUntilDocumentOrError(ctx context.Context, operation *operation) (*operationResult, error) {
37 cursor, err := entities(ctx).cursor(operation.Object)
38 if err != nil {
39 return nil, err
40 }
41
42
43 if cursor.Next(ctx) {
44
45 var res bson.Raw
46 if err := cursor.Decode(&res); err != nil {
47 return nil, fmt.Errorf("error decoding cursor result: %w", err)
48 }
49
50 return newDocumentResult(res, nil), nil
51 }
52 return newErrorResult(cursor.Err()), nil
53 }
54
View as plain text