Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the difference between Op.Data and Op.Doc ? #24

Open
cmfunc opened this issue Oct 13, 2020 · 1 comment
Open

What is the difference between Op.Data and Op.Doc ? #24

cmfunc opened this issue Oct 13, 2020 · 1 comment

Comments

@cmfunc
Copy link

cmfunc commented Oct 13, 2020

type Op struct {
	Id                interface{}            `json:"_id"`
	Operation         string                 `json:"operation"`
	Namespace         string                 `json:"namespace"`
	Data              map[string]interface{} `json:"data,omitempty"`
	Timestamp         primitive.Timestamp    `json:"timestamp"`
	Source            QuerySource            `json:"source"`
	Doc               interface{}            `json:"doc,omitempty"`
	UpdateDescription map[string]interface{} `json:"updateDescription,omitempty"`
	ResumeToken       OpResumeToken          `json:"-"`
}

I want to get latest document that have been change. for example, in "lessons" mongo collections, I update "$unset" the "room_id" filed of "lessons" collections , I need the doc data without "room_id" field.
I shouled select Op.Data and Op.Doc ? Op.Doc is value of Op.Data field "Doc" ?

@rwynn
Copy link
Owner

rwynn commented Oct 13, 2020

Op.Data was added first, it is your MongoDB data as a go map. Later, Op.Doc was added so that the type could be changed to interface{}. This allows one to do custom unmarshalling into your own struct.

https://github.com/rwynn/gtm#custom-unmarshalling

If you don't do any custom unmarshalling into your own struct, then both fields get the go map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants