[GODRIVER-922] Filed Lenght Created: 02/Apr/19  Updated: 22/Apr/19  Resolved: 22/Apr/19

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: 1.0.0-rc2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Sebastian Gogoasa Assignee: Isabella Siu (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac



 Description   

Fields having 3 characters are not stored:

...
type CheckResults struct { 
  domain string
  rct    string
  rst    string
  stt    string
  spt    string
  rsc    int
  rsm    string
}
...
 
func main() {
...
    PostResults := CheckResults{"domain.tld", "rct-example", "rst-example", "stt-example", "spt-example", 100, "rsm-example"}
...
}

This will create (in my code) a collection, a document but no fields and data, not even for "domain".

If I do change the length of these for example DomainName, RecordTime and so on the data will get stored.

 



 Comments   
Comment by Isabella Siu (Inactive) [ 05/Apr/19 ]

Hi sebastiang,
The reason that the fields are not pushed in your second case is because the struct fields are private. If you use public fields with capitalized names, they will be added to the document.

Comment by Sebastian Gogoasa [ 05/Apr/19 ]

Sorry for the delay,

Here's my code:

package mainpackage main
import ( "context" "fmt" "log" "time"
 "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options")
type CollectedData struct { DomainName, RecordTime, ResponseTime, StartTime, StopTime, ResponseCode, ResponseMessage string}
func main() {
 ctx, _ := context.WithTimeout(context.TODO(), 10*time.Second) client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
 if err != nil { log.Fatal(err) }
 // BGN: Check the connection err = client.Ping(context.TODO(), nil)
 if err != nil { log.Fatal(err) }
 fmt.Println("Connected to MongoDB!") // EOF: Check the connection
 CurrentDateTime := time.Now() CollectionName := CurrentDateTime.Format("012006") collection := client.Database("HttpStatusCodes").Collection(CollectionName)
 PostData := CollectedData{"domain.com", "rct01", "rst01", "stt01", "spt01", "rsc01", "rsm01"}
 InsertResult, err := collection.InsertOne(context.TODO(), PostData) if err != nil { log.Fatal(err) }
 fmt.Println("Inserted a single document:", InsertResult.InsertedID)
 if err != nil { log.Fatal(err) }
 err = client.Disconnect(context.TODO()) fmt.Println("Connection to MongoDB closed.")
}

Sorry for the code formatting...

 

So if I change the struct code to this:

type CheckResults struct {type CheckResults struct { 
domain string 
rct    string 
rst    string 
stt    string 
spt    string 
rsc    string // this was Int initially, not sure if that affects in any way
rsm    string}

It won't save any of my values passed:

PostData := CollectedData{"domain.com", "rct01", "rst01", "stt01", "spt01", "rsc01", "rsm01"}

The document will be created but no data or fields pushed.

 

 

Comment by Ian Whalen (Inactive) [ 04/Apr/19 ]

sebastiang could you please provide a fully executable main() for us to repro the problem you're seeing?

Generated at Thu Feb 08 08:35:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.