Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1610

bson.M can't be used as a sort document

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.3.2, 1.3.3
    • Component/s: CRUD
    • None
    • Environment:
      when use multi field to sort, probably different results

      type AB struct

      { A int32 bson:"A" B int32 bson:"B" }

      func TestSort(t *testing.T) {
      mongodb.Init()
      defer mongodb.Close()

      mongodb.GetTrainingDB().Collection("TestSort").Drop(context.Background())

      for i := 0; i < 5; i++ {
      mongodb.GetTrainingDB().Collection("TestSort").InsertOne(context.Background(), bson.M

      {"A": i, "B": rand.Int31n(10)}

      )
      mongodb.GetTrainingDB().Collection("TestSort").InsertOne(context.Background(), bson.M

      {"A": i, "B": rand.Int31n(10)}

      )
      }

      for i := 0; i < 100; i++ {
      sortABList := []AB{}
      theOption := options.Find().SetSort(bson.M

      {"A": -1, "B": -1}

      )
      theCur, _ := mongodb.GetTrainingDB().Collection("TestSort").Find(context.Background(), bson.M{}, theOption)
      defer theCur.Close(context.Background())

      for theCur.Next(context.Background())

      { var theValue AB theCur.Decode(&theValue) sortABList = append(sortABList, theValue) }

      for i := 0; i < len(sortABList)-1; i++ {
      fmt.Println(sortABList[i])
      if sortABList[i].A < sortABList[i+1].A

      { t.Fatalf("sort error! %d less then %d", sortABList[i].A, sortABList[i+1].A) }

      }
      fmt.Println()
      }

      }

            Assignee:
            Unassigned Unassigned
            Reporter:
            kaobkaob0812@gmail.com TheKaobkaob .
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: