Skip to content

Example for builder.Lookup with SimpleAggregate please #89

Open
@suntong

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions