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

Is it possible to populate without `_id` ? #2562

Closed
mocheng opened this issue Dec 26, 2014 · 82 comments
Closed

Is it possible to populate without `_id` ? #2562

mocheng opened this issue Dec 26, 2014 · 82 comments
Labels
Milestone

Comments

@mocheng
Copy link
Contributor

@mocheng mocheng commented Dec 26, 2014

I checked the API http://mongoosejs.com/docs/populate.html and tried out. It seems that populate can only works on foreign _id. Even there is a match option, it just add more filtering condition on _id query condition. There is no way to just populate with fields not involved with _id.

In my project, we keep the _id as ObjectId and has another field as auto-increment Number. For example, customers model has _id as Object and cuid as incremental number. Other collections just reference to cuid not to _id.

Is would be great to be able to customize this?
Is there any design limitation causing this feature missing?

@vkarpov15
Copy link
Collaborator

@vkarpov15 vkarpov15 commented Jan 1, 2015

It would be great to be able to customize this, but right now we enforce _id. I can't think of a good reason off the top of my head why not though. I'll have to investigate further.

@taxilian
Copy link
Contributor

@taxilian taxilian commented Feb 19, 2015

The ability to populate not just on a single other field but even on a set of fields is almost required to properly support sharding, which is a huge use case for us.

For example, we have a collection "students" which may have a shard key for "subscription"; when we populate student data from our sections model (which contains an array of students) we have the subscription on the document but it will only look up based on the _id stored in "student" rather than allowing us to specify that it should also map the documents "assignment" field to "assignment" on the student.

Since we'd then be doing a lookup without the shard key when doing populate it renders sharding useless, requiring all shards to be hit to retrieve the data instead of just one.

This is something we would be willing to fund development for or even do ourselves if we could get some guidance of where to do the work. It is a major need for our company (GradeCam).

@vkarpov15
Copy link
Collaborator

@vkarpov15 vkarpov15 commented Feb 20, 2015

@taxilian are you setting the shardKey schema option? AFAIK that's what that option is for.

@taxilian
Copy link
Contributor

@taxilian taxilian commented Feb 20, 2015

I haven't actually moved to start doing it yet because I've been looking for a solution to this issue; does populate take into account shardKey? My understanding was that shardKey only affected updates and inserts

@arliber
Copy link

@arliber arliber commented Apr 19, 2015

It would be great to be able to specify the field which is to be "joined by", for example I'd like to be able to populate not only by userId (i.e. _id) field but also by userType, userGroup etc.
Thanks!

@podoler
Copy link

@podoler podoler commented Apr 19, 2015

+1

@nadavsinai
Copy link

@nadavsinai nadavsinai commented Apr 30, 2015

+1 would be very useful

@xr
Copy link

@xr xr commented May 9, 2015

+1 same here!

@prakash122
Copy link

@prakash122 prakash122 commented May 21, 2015

+1 love to have this

@ricolo
Copy link

@ricolo ricolo commented May 24, 2015

+1

1 similar comment
@vlapo
Copy link

@vlapo vlapo commented Jun 4, 2015

+1

@prescottprue
Copy link

@prescottprue prescottprue commented Jun 8, 2015

+1

It would be especially nice to be able to select the variable you would like to populate with by adding a parameter such as key:

For example if had posts that I wanted to populate the author and comments parameters of, but the parameters are holding non ObjectId parameters (username of user and title of comments) before population:

{
author: "user1",
comments:["comment5", "comment6"],
title:"Post1"
}

It would be nice to be able to add a parameter like "key" to let mongo know which parameter to lookup by:

Posts.find().populate([{path:"author", model:"Users", key:"username"}, {path:"comments", model:"Comments", key:"title"}])

This would fill the author parameter with a User found by username as well as fill the comments parameter with comments found by their title (I realize the comments by title is a little unrealistic, but you get the point).

@apankov
Copy link

@apankov apankov commented Jun 10, 2015

+1

6 similar comments
@marklar21
Copy link

@marklar21 marklar21 commented Jul 14, 2015

+1

@john-bower
Copy link

@john-bower john-bower commented Jul 31, 2015

+1

@jack-guy
Copy link

@jack-guy jack-guy commented Aug 9, 2015

+1

@asafam
Copy link

@asafam asafam commented Aug 23, 2015

+1

@whyhankee
Copy link
Contributor

@whyhankee whyhankee commented Aug 25, 2015

+1

@ArcoMul
Copy link

@ArcoMul ArcoMul commented Aug 25, 2015

+1

@cannonpalms
Copy link

@cannonpalms cannonpalms commented Sep 3, 2015

Big agree. I'd love the ability to define custom population schemes. It'd be great for any schema with one or more fields that are file paths, allowing populate to read from storage.

@raphaelokon
Copy link

@raphaelokon raphaelokon commented Sep 11, 2015

+1

8 similar comments
@naoxink
Copy link

@naoxink naoxink commented Sep 14, 2015

+1

@manasb-uoe
Copy link

@manasb-uoe manasb-uoe commented Oct 6, 2015

+1

@Poplava
Copy link

@Poplava Poplava commented Oct 9, 2015

+1

@lfk
Copy link

@lfk lfk commented Oct 20, 2015

+1

@RithwikAnand
Copy link

@RithwikAnand RithwikAnand commented Oct 31, 2015

+1

@justvisiting
Copy link

@justvisiting justvisiting commented Nov 6, 2015

+1

@kumasento
Copy link
Contributor

@kumasento kumasento commented Nov 13, 2015

+1

@BentoumiTech
Copy link

@BentoumiTech BentoumiTech commented Nov 14, 2015

+1

@ingoncalves
Copy link

@ingoncalves ingoncalves commented Apr 4, 2016

+1

10 similar comments
@markotom
Copy link

@markotom markotom commented Apr 7, 2016

+1

@forksofpower
Copy link

@forksofpower forksofpower commented Apr 12, 2016

+1

@ashe540
Copy link

@ashe540 ashe540 commented Apr 16, 2016

+1

@BenBestmann
Copy link

@BenBestmann BenBestmann commented Apr 26, 2016

+1

@realbisoye
Copy link

@realbisoye realbisoye commented May 11, 2016

+1

@rychkog
Copy link

@rychkog rychkog commented May 13, 2016

+1

@atamas101
Copy link

@atamas101 atamas101 commented May 18, 2016

+1

@mogita
Copy link

@mogita mogita commented May 19, 2016

+1

@samidarko
Copy link

@samidarko samidarko commented May 20, 2016

+1

@zing777
Copy link

@zing777 zing777 commented Jun 7, 2016

+1

vkarpov15 added a commit that referenced this issue Jun 9, 2016
vkarpov15 added a commit that referenced this issue Jun 10, 2016
vkarpov15 added a commit that referenced this issue Jun 13, 2016
Expose mongoose-populate-virtuals API in core
@vkarpov15 vkarpov15 closed this Jun 13, 2016
@oguzhanaslan
Copy link

@oguzhanaslan oguzhanaslan commented Jun 28, 2016

+1

@thatisuday
Copy link

@thatisuday thatisuday commented Jul 20, 2016

@atakangktepe
Copy link

@atakangktepe atakangktepe commented Oct 6, 2016

+1

@anaibol
Copy link

@anaibol anaibol commented Oct 26, 2016

+1

@teemuniiranen
Copy link

@teemuniiranen teemuniiranen commented Feb 17, 2017

+1

2 similar comments
@coderafei
Copy link

@coderafei coderafei commented Mar 2, 2017

+1

@fbegue
Copy link

@fbegue fbegue commented Mar 26, 2017

+1

@anaibol
Copy link

@anaibol anaibol commented Mar 30, 2017

+3

@omarps
Copy link

@omarps omarps commented Jun 16, 2017

+1

@Automattic Automattic locked and limited conversation to collaborators Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.