zebresel-com / mongodm Goto Github PK
View Code? Open in Web Editor NEWA golang object document mapper (ODM) for MongoDB
License: GNU General Public License v2.0
A golang object document mapper (ODM) for MongoDB
License: GNU General Public License v2.0
In my opinion, For more developers to contributing code to this repository easily like most open source project, I think you should do something as below:
BTW, I can submit PRs for step 1-3, let me know your decision by reply, thank you.
Currently when I call the .Find()
method on a model, and follow that up with a .Populate()
, I get the following error: Given models were not correctly initialized with 'DocumentBase' interface type
.
This is weird as calling .Populate()
on the same model but instead of .Find()
I use .FindId()
it works ?
Problem:
type ModelA struct {
mongodm.DocumentBase `json:",inline" bson:",inline"`
Target bson.ObjectId `json:"target" bson:"target"`
}
if create a ModelA
but leave target
field empty, when try to save the document, error occured:
ObjectIDs must be exactly 12 bytes long (got 0)
. So, maybe need add something like this:
Target bson.ObjectId `sparse:"true"`
?
I have built an executable of my go application which uses zebresel-com/mongodm and am trying to deploy it in docker container, but I am getting the following error.It is working great on my linux box but it fails when I try to deploy it inside docker.
" initialization failed: open /home/myuser/work/pkg/mod/github.com/zebresel-com/[email protected]+incompatible/locals.json: no such file or directory"
Steps to reproduce:
.. would be more community friendly. Any other suggestions?
currently i have a model that is as the following
ConfirmedGuests []interface{} `model:"Guest" relation:"1n" autosave:"true"`
In the flow that I have in my backend, I get the data for the guests and the data for the model that ConfirmedGuests
lives in. I first create all guests and put their bson.ObjectId
's in a slice. then I wish to assign them to ConfirmedGuests
. But since ConfirmedGuests
is of type []interface{}
and my guests slice is of type []bson.ObjectId
I cannot assign them when creating the struct ConfirmedGuests
lives in. Is there any way of assigning this through a clever cast or something ?
Regards, Duck
Hi there!
I was reading up on mongodm.Config
, and noticed that SetSocketTimeOut
, SetSafe
, and SetMode
were hardcoded instead of allowing users to pass them in via mongodm.Config
. Are there any plans to include this functionality in future releases? If you accept PRs, I'd be more than happy to add that in.
Currently it is not possible to populate a field in a model that is not top level.
Not allowing this sort of defeats the perpose of mongodb as it does not allow for proper nesting.
A solution for this would be to allow dot notated routes for structures.
According to Todos
, I will spend some days to work on virtuals and hooks (like in mongoose)
task.
how to find by relation?
For details see https://github.com/go-mgo/mgo
Database connection error: %v server returned error on SASL authentication step: Authentication failed.
I am trying to update a defined model with the following piece of code
connection := context.MustGet("dbConnection").(*mongodm.Connection)
Reservation := connection.Model("reservation")
reservation := &models.Reservation{}
err := context.BindJSON(r)
if err != nil {
context.AbortWithStatusJSON(500, apierrors.JsonBindingError)
return
}
err = Reservation.FindId(id).Exec(reservation)
if err != nil {
context.AbortWithStatusJSON(500, apierrors.DBLookupFailedError)
}
err, _ = reservation.Update(bson.M{
"IsSharedRoom": r.IsSharedRoom,
"Beds": r.Beds,
"PartySize": r.PartySize,
"notes": r.Notes,
"ConfirmedGuest": r.ConfirmedGuest,
"RoomType": r.RoomType,
"CheckinDate": r.CheckinDate,
"CheckoutDate": r.CheckoutDate,
"ReservationNumber": r.ReservationNumber,
})
however, when this code is ran, nothing in the database is updated on the model, is there something I am missing ? I also could not find any documentation on how to use this function other than that it can be used on an IDocumentBase
Regards Duck
Currently, I have an array of object id's which are coming in from the frontend to my backend API. I wish to save these as ObjectId's in the backend so i can later populate them when i need to send the whole object back to the frontend. But as it currently stands, if i save the raw objectId's, it will save them as type String
and not ObjectId
. Is there a way around this ?
Many thanks
Are you sure you want to keep the informations related to docker into the contribute file?
It's a bit unnatural to look for these infos there.
Just a thought
Index
topic not found in any code, issue or document...
Hello there,
I was wondering if there is a possible bug with how the relation
tag is handled. I have an Email
model that holds the sender's email and a slice of recipients. I only want to store the recipient's email, and not the entire user object. The model is written as follows:
type Email struct {
mongodm.DocumentBase `json:",inline" bson:",inline"`
From string `json:"from" bson:"from"`
To []string `json:"to" bson:"to"`
}
I am failing validation on the To
field with validation.field_invalid_relation1n
. Looking through the document_base.go file I found the following code:
if fieldValue.Kind() == reflect.Slice && relationTag != REL_1N {
self.AppendError(&validationErrors, L("validation.field_invalid_relation1n", validationName))
} else if fieldValue.Kind() != reflect.Slice && relationTag == REL_1N {
self.AppendError(&validationErrors, L("validation.field_invalid_relation11", validationName))
}
Shouldn't there be another check inside the if block to see if relationTag != ""
? Without it, every slice would have to be a relation even though it doesn't need to be.
Hi, I am new with golang and I tried to use your library and I get the following error
middlewares/main.go:76: cannot use model (type models.Model) as type mongodm.IDocumentBase in argument to ModelCollection.New:
models.Model does not implement mongodm.IDocumentBase (DefaultValidate method has pointer receiver)
I have emmbeded the struct mongodm.DocumentBase
on my definition, what is my problem ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.