@@ -458,35 +458,38 @@ func indexDocsEqual(expected, actual bsoncore.Document) (bool, error) {
458
458
return true , nil
459
459
}
460
460
461
- keyElemElems , err := actual .Elements ()
461
+ actualElems , err := actual .Elements ()
462
462
if err != nil {
463
463
return false , err
464
464
}
465
- modelKeysElems , err := expected .Elements ()
465
+ expectedElems , err := expected .Elements ()
466
466
if err != nil {
467
467
return false , err
468
468
}
469
469
470
- if len (keyElemElems ) != len (modelKeysElems ) {
470
+ if len (actualElems ) != len (expectedElems ) {
471
471
return false , nil
472
472
}
473
473
474
- for _ , elem := range keyElemElems {
475
- key := elem .Key ()
476
- modelVal , err := expected .LookupErr (key )
477
- if err != nil {
474
+ for idx , expectedElem := range expectedElems {
475
+ actualElem := actualElems [idx ]
476
+ if actualElem .Key () != expectedElem .Key () {
478
477
return false , nil
479
478
}
480
479
481
- val := elem .Value ()
482
- if ! val .IsNumber () || ! modelVal .IsNumber () {
483
- if val .Equal (modelVal ) {
480
+ actualVal := actualElem .Value ()
481
+ expectedVal := expectedElem .Value ()
482
+ actualInt , actualOK := actualVal .AsInt64OK ()
483
+ expectedInt , expectedOK := expectedVal .AsInt64OK ()
484
+
485
+ if ! actualOK || ! expectedOK {
486
+ if actualVal .Equal (expectedVal ) {
484
487
continue
485
488
}
486
489
return false , nil
487
490
}
488
491
489
- if val . AsInt64 () != modelVal . AsInt64 () {
492
+ if actualInt != expectedInt {
490
493
return false , nil
491
494
}
492
495
}
@@ -509,29 +512,25 @@ func createIndexIfNotExists(ctx context.Context, iv mongo.IndexView, model mongo
509
512
}
510
513
modelKeysDoc := bsoncore .Document (modelKeysBytes )
511
514
512
- var found bool
513
- for c .Next (ctx ) && ! found {
515
+ for c .Next (ctx ) {
514
516
keyElem , err := c .Current .LookupErr ("key" )
515
517
if err != nil {
516
518
return err
517
519
}
518
520
519
521
keyElemDoc := bsoncore.Value {Type : keyElem .Type , Data : keyElem .Value }.Document ()
520
522
521
- found , err = indexDocsEqual (modelKeysDoc , keyElemDoc )
523
+ found , err : = indexDocsEqual (modelKeysDoc , keyElemDoc )
522
524
if err != nil {
523
525
return err
524
526
}
525
- }
526
-
527
- if ! found {
528
- _ , err = iv .CreateOne (ctx , model )
529
- if err != nil {
530
- return err
527
+ if found {
528
+ return nil
531
529
}
532
530
}
533
531
534
- return nil
532
+ _ , err = iv .CreateOne (ctx , model )
533
+ return err
535
534
}
536
535
537
536
// create indexes on the files and chunks collection if needed
0 commit comments