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
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@mocheng
Copy link
Contributor

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 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.

@vkarpov15 vkarpov15 added the enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature label Jan 1, 2015
@taxilian
Copy link
Contributor

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 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 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 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 commented Apr 19, 2015

+1

@nadavsinai
Copy link

nadavsinai commented Apr 30, 2015

+1 would be very useful

@xr
Copy link

xr commented May 9, 2015

+1 same here!

@prakash122
Copy link

prakash122 commented May 21, 2015

+1 love to have this

@ricolo
Copy link

ricolo commented May 24, 2015

+1

1 similar comment
@vlapo
Copy link

vlapo commented Jun 4, 2015

+1

@prescottprue
Copy link

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 commented Jun 10, 2015

+1

6 similar comments
@marklar21
Copy link

marklar21 commented Jul 14, 2015

+1

@john-bower
Copy link

john-bower commented Jul 31, 2015

+1

@jack-guy
Copy link

jack-guy commented Aug 9, 2015

+1

@asafam
Copy link

asafam commented Aug 23, 2015

+1

@whyhankee
Copy link
Contributor

whyhankee commented Aug 25, 2015

+1

@ArcoMul
Copy link

ArcoMul commented Aug 25, 2015

+1

@cannonpalms
Copy link

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 commented Sep 11, 2015

+1

8 similar comments
@naoxink
Copy link

naoxink commented Sep 14, 2015

+1

@manasb-uoe
Copy link

manasb-uoe commented Oct 6, 2015

+1

@Poplava
Copy link

Poplava commented Oct 9, 2015

+1

@lfk
Copy link

lfk commented Oct 20, 2015

+1

@RithwikAnand
Copy link

RithwikAnand commented Oct 31, 2015

+1

@justvisiting
Copy link

justvisiting commented Nov 6, 2015

+1

@kumasento
Copy link
Contributor

kumasento commented Nov 13, 2015

+1

@BentoumiTech
Copy link

BentoumiTech commented Nov 14, 2015

+1

@ingoncalves
Copy link

ingoncalves commented Apr 4, 2016

+1

10 similar comments
@markotom
Copy link

markotom commented Apr 7, 2016

+1

@forksofpower
Copy link

forksofpower commented Apr 12, 2016

+1

@ashe540
Copy link

ashe540 commented Apr 16, 2016

+1

@BenBestmann
Copy link

BenBestmann commented Apr 26, 2016

+1

@realbisoye
Copy link

realbisoye commented May 11, 2016

+1

@rychkog
Copy link

rychkog commented May 13, 2016

+1

@atamas101
Copy link

atamas101 commented May 18, 2016

+1

@mogita
Copy link

mogita commented May 19, 2016

+1

@samidarko
Copy link

samidarko commented May 20, 2016

+1

@zing777
Copy link

zing777 commented Jun 7, 2016

+1

@oguzhanaslan
Copy link

oguzhanaslan commented Jun 28, 2016

+1

@thatisuday
Copy link

thatisuday commented Jul 20, 2016

#4348

@atakangktepe
Copy link

atakangktepe commented Oct 6, 2016

+1

@anaibol
Copy link

anaibol commented Oct 26, 2016

+1

@teemuniiranen
Copy link

teemuniiranen commented Feb 17, 2017

+1

2 similar comments
@terry-fei
Copy link

terry-fei commented Mar 2, 2017

+1

@fbegue
Copy link

fbegue commented Mar 26, 2017

+1

@anaibol
Copy link

anaibol commented Mar 30, 2017

+3

@omarps
Copy link

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.
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

No branches or pull requests