GithubHelp home page GithubHelp logo

zebresel-com / mongodm Goto Github PK

View Code? Open in Web Editor NEW
197.0 12.0 33.0 73 KB

A golang object document mapper (ODM) for MongoDB

License: GNU General Public License v2.0

Go 99.54% Makefile 0.46%
mongodb golang golang-library mapper odm document-mapper

mongodm's Issues

Slices always viewed as relations

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.

Expanding mongodm.Config

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.

About contributing

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:

  1. Dockerized. To unified environment of development.
  2. Writing test. To make CI easily.
  3. Building by CI.
  4. Create a CONTRIBUTE.md. To guide those guys who want to contribute to this repository.

BTW, I can submit PRs for step 1-3, let me know your decision by reply, thank you.

Put docker infos back to readme?

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

Assigning a 1n relation

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

Populating on .Find()

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 ?

1n relation. saving objectId's and populating them

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

Getting Error does not implement DefaultValidate

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 ?

using Documentbase.Update()

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

Fatal error, mongodb initialization failed: open /home/user/work/pkg/mod/github.com/zebresel-com/[email protected]+incompatible/locals.json: no such file or directory"

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:

  1. Create a go executable of work repo which is using zebresel-com/mongodm
  2. Copy the executable in docker env via Docker copy command through Dockerfile

Need to add `sparse` annotation support to model field

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"`

?

mongodb3.0 SCRAM-SHA-1?

Database connection error: %v server returned error on SASL authentication step: Authentication failed.

Allow nested fields to be populated

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.