How to manage relationship in go-mongo?
I am trying as follows but not working:
type Post struct {
ID primitive.ObjectID `json:"id" bson:"_id"`
Text string `json:"text" bson:"text,omitempty"`
Comments …
I try to make get all data with Name field where I specify in API Request Body. I made a filter for .Find() function. But I can't get any result (response body says null, No errors at all). You can see my model file and other parts of the code at…
I have an array of objects along with other fields in a mongodb document:
db.config.find({},{list_attributes:1, _id:0});
[
{
list_attributes: {
'0': { field: 'LASTNAME', field_key: 'lastname', dataType: 'text' },
'1': { field:…
I am trying something simple using the mongo-go-driver.
I insert some datas in a collection, and I want them to be automaticaly deleted after a number of seconds.
I have read the following documentation :…
I have 2 structs:
type Customer struct {
MyID int `bson:"myID"`
}
type Bag struct {
Customer primitive.ObjectID `bson:"customer"`
}
But I dunno how to make filter to find document in Bag collection by Customer.MyID
I tried something like…
I am facing a issue with update document using golang mongo driver.
Scenario: I want to update a field that is nested in a struct. For ex: StructOuter -> structInner -> field1, field2, field3. Now if I want to update the field3 and I have the…
I try to create a MongoDB query filter with the nested operators (OR/AND/...). But lib requires to create a bson.D and pass bson.E elements into it. If I need to have OR/AND inside AND/OR - I need to put bson.M + bson.D inside bson.D like…
I am trying to make a query using the ObjectId, and normally in mongodb you would do something like this
db.collection.findOne({"_id":objectid("5d9d90e5ed645489aae6df64")})
Which this works when I do a normal query but in go lang it gives it the…
I have this struct and when I decode it from the database to struct I'm getting this error cannot decode array into an ObjectID
type Student struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
...
Hitches …
Question
How can I list databases only with the given prefix (prefix_)?
Example:
package main
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
…
I need to do addToSet operation using official Go MongoDB driver.
In MongoDB we have some docs:
{ _id: 2, item: "cable", tags: [ "electronics", "supplies" ] }
Then to perform addToSet:
db.inventory.update(
{ _id: 2 },
{ $addToSet: { tags: {…
Go Version: 1.12.5
I have this code which uses the node.js mongo driver
const MongoClient = require('mongodb').MongoClient;
const uri = process.env.MONGO_HOST + "dbname?retryWrites=true";
const client = new MongoClient(uri, {
useNewUrlParser:…