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

when use $in []uint8 query in go , will get (BadValue) $in needs an array

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 1.8.1
    • Component/s: CRUD

      Summary

      When using the go mongodb driver,  $in query, the (BadValue) $in needs an array error occurs if [] uint8 is used for the query.

      bug may be ? Our business has been affected.

      mongo-driver v1.8.1

       mongodb instance is a shard cluster

       

      $ mongo --host 192.168.64.6
      MongoDB shell version v4.0.3
      connecting to: mongodb://192.168.64.6:27017/
      Implicit session: session { "id" : UUID("e4d7cea2-ab81-45ad-a51e-e7acf45a7242") }
      MongoDB server version: 4.4.8
      WARNING: shell and server versions do not match
      
      mongos> use testing
      switched to db testing
      mongos> db.numbers.find()
      { "_id" : ObjectId("61b71d3d73b251bceee62032"), "type" : 0, "value" : 0 }
      { "_id" : ObjectId("61b71d3d73b251bceee62033"), "type" : 1, "value" : 1 }
      { "_id" : ObjectId("61b71d3d73b251bceee62034"), "type" : 2, "value" : 2 }
      { "_id" : ObjectId("61b71d3d73b251bceee62035"), "type" : 3, "value" : 3 }
      { "_id" : ObjectId("61b71d3d73b251bceee62036"), "value" : 4, "type" : 4 }
      { "_id" : ObjectId("61b71d3d73b251bceee62037"), "value" : 5, "type" : 5 }
      { "_id" : ObjectId("61b71d3d73b251bceee62038"), "type" : 6, "value" : 6 }
      { "_id" : ObjectId("61b71d3d73b251bceee62039"), "type" : 7, "value" : 7 }
      { "_id" : ObjectId("61b71d3d73b251bceee6203a"), "type" : 8, "value" : 8 }
      { "_id" : ObjectId("61b71d3d73b251bceee6203b"), "type" : 9, "value" : 9 }
      mongos>​
      

       

       

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      How to Reproduce

      package main
      
      import (
      	"context"
      	"fmt"
      	"time"
      
      	"go.mongodb.org/mongo-driver/mongo"
      	"go.mongodb.org/mongo-driver/mongo/options"
      	"gopkg.in/mgo.v2/bson"
      )
      
      func main() {
      	// init mongodb client
      	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
      	defer cancel()
      	client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://192.168.64.6:27017/"))
      	if err != nil {
      		fmt.Println(err)
      		return
      	}
      
      	// mock some data
      	collection := client.Database("testing").Collection("numbers")
      	for i := 0; i < 10; i++ {
      		_, err = collection.InsertOne(ctx, bson.M{"type": uint8(i), "value": i})
      		if err != nil {
      			fmt.Println(err)
      			return
      		}
      	}
      
      	// query
      	filter := bson.M{"type": bson.M{"$in": []uint8{1, 2, 3}}}
      	res := collection.FindOne(ctx, filter)
      	if err = res.Err(); err != nil {
      		fmt.Println(err)
      		return
      	}
      }
      ​
      
      go run main.go
      
      (BadValue) $in needs an array​
      

      Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

      Additional Background

      Please provide any additional background information that may be helpful in diagnosing the bug.

            Assignee:
            benji.rewis@mongodb.com Benji Rewis (Inactive)
            Reporter:
            sinksmell@163.com sink smell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: