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

How to Limiting Relation? #12

Open
radiegtya opened this issue Dec 3, 2016 · 5 comments
Open

How to Limiting Relation? #12

radiegtya opened this issue Dec 3, 2016 · 5 comments

Comments

@radiegtya
Copy link

Just wanna ask how to limit fetched relations?

for example if the relational table has 1000+ rows.

for example:

Projects

_id,
name,

Meteor.users

_id,
username,

ProjectMembers

_id,
projectId,
userId

ProjectMembers.join(Meteor.users, ....)

then ProjectMembers may have so many users inside

@perak
Copy link
Owner

perak commented Dec 3, 2016

@radiegtya you can contoll it when publishing/subscribing to ProjectMembers (paged subscribing chunk by chunk)

@radiegtya
Copy link
Author

radiegtya commented Dec 3, 2016

then the one which is limiting is ProjectMembers it self. not the user inside it??
If you can limit the user inside it, please give example how to do it. Regards

both.js

ProjectMembers.join(Meteor.users, "userId", "user", ["username", "profile"]);

server.js

Meteor.publish('projectMembers', (selector = {}, options = {})=>{
      const cursor = ProjectMembers.find(selector, options);
      return ProjectMembers.publishJoinedCursors(cursor);
});

client.js

const limit = 5; //for example limiting 5
const myProjectId = "23456asdasda";

this.autorun(()=>{
  this.subscribe('projectMembers', 
      {projectId: myProjectId, "user.username": {$regex: "", $options: 'i'}},
      {limit: limit}
  );
});

@perak
Copy link
Owner

perak commented Dec 3, 2016

Yes, that will return 5 priject members only (with user data).

@perak
Copy link
Owner

perak commented Dec 3, 2016

(tou can also combine with "skip" option (and youll need to pass skip and limit as arguments to publish, and sort in the same order both at client and at server).

@radiegtya
Copy link
Author

radiegtya commented Dec 3, 2016 via email

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