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

Example for builder.Lookup with SimpleAggregate please #89

Open
suntong opened this issue Oct 30, 2023 · 0 comments
Open

Example for builder.Lookup with SimpleAggregate please #89

suntong opened this issue Oct 30, 2023 · 0 comments
Assignees

Comments

@suntong
Copy link

suntong commented Oct 30, 2023

Is your feature request related to a problem? Please describe.

How to use builder.Lookup with SimpleAggregate?

Describe the solution you'd like

Please add one more example using SimpleAggregate with builder.Lookup into
https://github.com/Kamva/mgm/blob/master/examples/aggregate/aggregate.go

Describe alternatives you've considered
Additional context

I tried it myself, adding the following to the top of func lookup(), after:

func lookup() error {
seed()
defer delSeededData()

{
	authorCollName := mgm.Coll(&author{}).Name()
	result := []book2{}
	_ := mgm.Coll(&book{}).SimpleAggregate(&result, builder.Lookup(authorCollName, "auth_id", "_id", "author"))
	fmt.Printf("1] %+v\n", result)
}

after defining book2 as:

type book2 struct {
	book
	author []author
}

However, what get printed was:

1] [{book:{DefaultModel:{IDField:{ID:ObjectID("000000000000000000000000")} DateFields:{CreatedAt:0001-01-01 00:00:00 +0000 UTC UpdatedAt:0001-01-01 00:00:00 +0000 UTC}} Name: Pages:0 AuthorID:ObjectID("000000000000000000000000")} author:[]}]

I.e., the lookup field author was empty, and so is the returned book, but the SimpleAggregate didn't return any error (I checked).

Please help.

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