| 123456789101112131415161718192021222324252627282930313233343536373839404142 | 
							- package mo
 
- import (
 
- 	"context"
 
- 	"testing"
 
- )
 
- func TestNewClient(t *testing.T) {
 
- 	client, err := NewClient("mongodb://root:abcd1234@localhost:27017/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false")
 
- 	if err != nil {
 
- 		t.Error(err)
 
- 		return
 
- 	}
 
- 	ctx, cancel := context.WithTimeout(context.Background(), DefaultTimout)
 
- 	defer cancel()
 
- 	// opts := options.CreateCollection().SetValidator(validator)
 
- 	cmd := D{{Key: "collMod", Value: "user"}, {"validator", E{Key: "$jsonSchema", Value: M{
 
- 		"bsonType": "object",
 
- 		"required": []string{"password"},
 
- 		"properties": M{
 
- 			"username": M{
 
- 				"bsonType":    "string",
 
- 				"description": "must be a string and is required",
 
- 			},
 
- 			"password": M{
 
- 				"bsonType":    "long",
 
- 				"description": "must be a long and is required",
 
- 			},
 
- 		},
 
- 	}}}}
 
- 	r := client.Database("ums").RunCommand(ctx, cmd)
 
- 	if err := r.Err(); err != nil {
 
- 		t.Error(err)
 
- 	}
 
- }
 
- func TestNewObjectID(t *testing.T) {
 
- 	t.Log(NewObjectID().Hex())
 
- }
 
 
  |