I have a collections of 2,000,000 records
> db.events.count(); │
2000000
and I use golang mongodb client to connect to the database
package main
import (
"go.mongodb.org/mongo-driver/bson"
…
I am a beginner in mongo with go. I am trying to find one document where "username" or email will be matched. But can't figure out the way to implement this condition to filter.
Here is my document model:
type User struct {
Username string …
While working on Golang Mongo Driver, I am stuck with this weird beahviour to use inline
Seems like bson:",inline" doesnt work with Embedded Structs.
Not able to understand why such a behaviour?
inline Inline the field, which must be a struct or…
Based on the documentation, go.mongodb.org/mongo-driver doesn't seem to provide a way to auto-increment ID when it is upserting a document that has not provided an ID.
type Document struct {
ID int `bson:"_id"`
Foo…
How to handle if document structure after production changes.
Suppose I had 500 documents like this:
{
name: ‘n1’
height: ‘h1’
}
Later if I decide to add all the documents in below format:
{
name: ‘n501’
height: ‘h501’
weight: ‘w501’
}
I am using…
I have a sample JSON body that contains some strings. I want some of the strings to be converted into Mongo Extended JSON. For example, the JSON body passed in is the following:
{
"GuidBinary": "734cba69-4851-4869-8d0e-e870d6fb3065",
…
I'm struggling to marshal/unmarshal bson array with polymorphic struct with mongo-go-driver。I plan to save a struct discriminator into the marshaled data, and write a custom UnmarshalBSONValue function to decode it according to the struct…
The GO driver for MongoDB has a Decimal128 type which is a struct that looks like this:
type Decimal128 struct {
h, l uint64
}
according to the docs, the h and l are high and low uint64 values. What do these two values represent? Let's say I…
I try to read and write and delete data from a Go application with the official mongodb driver for go (go.mongodb.org/mongo-driver).
Here is my struct I want to use:
Contact struct {
ID xid.ID `json:"contact_id" bson:"contact_id"`
…
I would like to have some kind of a "hook" that runs whenever I get a specific type of object from the database. I thought the Unmarshaler interface is perfect for that, but... How can I implement that interface without manually unmarshalling every…
In the community driven Mongo driver for Go, i.e. Mgo, we can use the Apply API call to run MongoDB queries involving $set or $inc. An example of this use-case in Mgo is as follows:
change := mgo.Change{
Update: bson.M{"$set":…