This is a creation in Article, where the information may have evolved or changed.
Problem description
When using MgO operation MongoDB, encountered data insertion is normal, but in the database view can only see Objectid is inserted, read, you can query to the record, but when the object is read, but all the values are 0 or empty case.
MONGODB Document Structure:
{ "_id": ObjectId ("502fbbd6fec1300be858767e"), "lastName": "Seba", " FirstName ": June" ,"inserted": Isodate ("2012-08-18t15:59:18.646z")}
Golang structure:
Type person struct { _id Bson. ObjectId firstName string middlename string lastName string inserted time . TIME}
Reason
When you use interface-defined fields across packages, you have access only in one of two situations. (See Go language Specification)
exported identifiers
An identifier is exported to permit access to it from the another package. An identifier is exported if both:
- The first character of the identifier ' s name is a Unicode upper case letter (Unicode Class "Lu"); and
- The identifier is declared in the package block or it is a field name or method name.
All other identifiers is not exported.
Solution Solutions
Capitalize the first letter of the object field. As shown below:
type person struct { Id Bson. ObjectId "_id" FirstName string "FirstName" middlename string " Middlename,omitempty " LastName string " LastName " Inserted time . Time "inserted"}