Error code:
type MongoConn struct {
clientOptions *options.ClientOptions
client *mongo.Client
collections *mongo.Collection
}
var mongoConn *MongoConn
func InitMongoConn() error{
ctx, cancelFunc := context.WithTimeout(context.Background(), 10*time.Second)
defer cancelFunc()
mongoUrl := "mongodb://" + user + ":" + password + "@" + url + "/" + dbname
mongoConn.clientOptions = options.Client().ApplyURI(mongoUrl)
//......
}
To solve the problem caused by pointer assignment:
var mongoConn MongoConn
Read More:
- [Go] Solve panic: runtime error: invalid memory address or nil pointer dereference in golang
- [Solved] Docker Startup Error: panic: runtime error: invalid memory address or nil pointer dereference
- Go Slice Error: panic:runtime error:index out of range [0] with length 0 [Solved]
- [Solved] Tsingsee green rhinoceros video pedestrian intelligence detection test error panic: runtime error
- [Solved] electron-builder Package mac Error: panic: runtime error: index out of range
- [Solved] leetcode Common Error: :runtime error: member access within misaligned address 0xbebebebebebebebe for type ‘str
- [Solved] runtime error: reference binding to null pointer of type ‘std::vector<int, std::allocator<int>>‘
- TensorRT model quantization error: Error Code 1: Cuda Runtime (an illegal memory access was encountered)
- How to Solve mount error(6): No such device or address
- [Solved] – npm run dev Error: listen EADDRINUSE: address already in use :::8000(or 8080 etc.)
- It can be opened with localhost, but not with IP address. The request host name is invalid
- [Solved] Go language gob serialization pointer cannot be addressed Error
- [Solved] Compilation error: dereferencing pointer to incomplete type…
- [Solved] panic: proto: duplicate enum registered: raftpb.EntryType
- Node Memory Overflow: FATAL ERROR: Reached heap limit Allocation failed – JavaScript heap out of memory
- [Solved] cocopod Error: failed: undefined method `map‘ for nil:NilClass
- [Solved] Searching for inspections failed: undefined method `map‘ for nil:NilClass“
- [Solved] Tensorflow error or keras error and tf.keras error: oom video memory is insufficient
- [How to Solve] Error: Invalid or corrupt jarfile…
- Error:scalac: missing or invalid dependency detected while loading class file ***