Hi All:
I’m creating a registration application using Meteor and Angular2 and I’m running into an issue where when I try to retrieve the list of campers associated with a particular registrant, in this case ‘guardian’, it’s returning the full camper collection.
I used the Meteor Socially tutorial as a baseline. Related code below:
packages:
meteor-base@1.0.4 # Packages every Meteor app needs to have
mobile-experience@1.0.4 # Packages for a great mobile UX
mongo@1.1.14 # The database Meteor supports right now
reactive-var@1.0.11 # Reactive variable for tracker
jquery@1.11.10 # Helpful client-side library
tracker@1.1.1 # Meteor's client-side reactive programming library
standard-minifier-css@1.3.2 # CSS minifier run for production mode
standard-minifier-js@1.2.1 # JS minifier run for production mode
es5-shim@4.6.15 # ECMAScript 5 compatibility for older browsers.
angular2-compilers
practicalmeteor:mocha
xolvio:cleaner
hwillson:stub-collections
dispatch:mocha-phantomjs
shell-server@0.2.1
accounts-password@1.3.3
accounts-facebook@1.0.11
accounts-google@1.0.11
tmeasday:publish-counts
email@1.1.18
aldeed:collection2
aldeed:autoform
twbs:bootstrap
fortawesome:fontawesome
alanning:roles
momentjs:moment
zuuk:stale-session
camper-form.component.ts:
addCamper(): void {
//alert('adding camper');
if (!Meteor.userId()) {
alert('Please log in to add a camper');
return;
}
if( this.camperForm.valid) {
//alert('form valid');
Campers.insert(Object.assign({}, this.camperForm.value, {guardian: Meteor.userId() }));
this.camperForm.reset();
}
}
camper-list.component.ts:
this.campers = Campers.find({}).zone();
this.campersSub = MeteorObservable.subscribe('campers').subscribe()
camper-list.component.html:
<div class="list-group" *ngFor="let camper of campers | async">
<a [routerLink]="['/dashboard/overview']" class="list-group-item">
<div class="row">
<div class="col-sm-8">
{{ camper.firstName }}
<span class="text-center small"><em>{{ camper.dob | date:'y'}}</em></span>
</div>
</div>
</a>
</div>
camper.ts publication:
Meteor.publish('campers', function() {
// Counts.publish(this, 'numberofCampers', Campers.collection.find({guardian: this.userId }), { noReady: true});
return Campers.find(buildQuery(this));
});
// Return a specific camper
Meteor.publish('camper', function(camperId: string) {
return Campers.find(buildQuery.call(this, camperId));
});
function buildQuery(camperId?: string): Object {
Counts.publish(this, 'numberofCampers', Campers.collection.find(), { noReady: true});
const isAvailable = {
$or: [{
public: true
},
// or
{
// current user is the owner
$and: [{
guardian: this.userId
}, {
guardian: {
$exists: true
}
}]
}]
};
if (camperId) {
return {
// only single camper
$and: [{
_id: camperId
},
isAvailable
]
};
}
return isAvailable;
}
meteor mongo query:
meteor:PRIMARY> db.campers.find({})
{ "_id" : "cTTosFNvfBEmkGpjz", "firstName" : "First1", "lastName" : "Last1", "dob" : "2007-05-14", "gender" : "F", "shirtSize" : "M", "swimLevel" : "Some", "relationship" : "Parent", "emergencyMain" : "5195555555", "emergencySecond" : "5195555555", "familyDoctorName" : "Dr
. D. Doctor", "familyDoctorPhone" : "5195555555", "specialNeeds" : "", "concerns" : "", "mementoConsent" : true, "websiteConsent" : true, "promoConsent" : "", "signoutConsent" : false, "signout1" : "", "signout2" : "", "signout3" : "", "guardian" : "CrFe6ktsAmKEga6Wp" }
{ "_id" : "oHaTY9b8WH5svESff", "firstName" : "First2", "lastName" : "Last2", "dob" : "2010-05-19", "gender" : "M", "shirtSize" : "M", "swimLevel" : "Some", "relationship" : "Legal guardian", "emergencyMain" : "5195555555", "emergencySecond" : "5195555555", "familyDoctorNam
e" : "Dr. D. Doctor", "familyDoctorPhone" : "5195555555", "specialNeeds" : "", "concerns" : "", "mementoConsent" : "", "websiteConsent" : "", "promoConsent" : "", "signoutConsent" : "", "signout1" : "", "signout2" : "", "signout3" : "", "guardian" : "CrFe6ktsAmKEga6Wp" }
{ "_id" : "7x7uisRxEad5ZRPtj", "firstName" : "First3", "lastName" : "Last3", "dob" : "2017-12-31", "gender" : "M", "shirtSize" : "S", "swimLevel" : "Weak", "relationship" : "Parent", "emergencyMain" : "5195555555", "emergencySecond" : "5195555555", "familyDoctorName" : "Dr
. D. Doctor", "familyDoctorPhone" : "5195555555", "specialNeeds" : "", "concerns" : "", "mementoConsent" : "", "websiteConsent" : "", "promoConsent" : "", "signoutConsent" : "", "signout1" : "", "signout2" : "", "signout3" : "", "guardian" : "9dATgEC2R5LBMNJNE" }
{ "_id" : "KDLahYGQt2rwNWNfJ", "firstName" : "First4", "lastName" : "Last4", "dob" : "2017-12-31", "gender" : "M", "shirtSize" : "L", "swimLevel" : "Some", "relationship" : "Family friend", "emergencyMain" : "5195555555", "emergencySecond" : "5195555555", "familyDoctorName
" : "Dr. D. Doctor", "familyDoctorPhone" : "5195555555", "specialNeeds" : "", "concerns" : "", "mementoConsent" : "", "websiteConsent" : "", "promoConsent" : "", "signoutConsent" : true, "signout1" : "", "signout2" : "", "signout3" : "", "guardian" : "XXCw56bLosgswzgmy" }
{ "_id" : "nWsFgEpyAnEvy8oru", "firstName" : "First5", "lastName" : "Last5", "dob" : "2015-11-30", "gender" : "F", "shirtSize" : "XL", "swimLevel" : "Some", "relationship" : "Other relative", "emergencyMain" : "5195555555", "emergencySecond" : "5195555555", "familyDoctorNa
me" : "Dr. D. Doctor", "familyDoctorPhone" : "5195555555", "specialNeeds" : "", "concerns" : "", "mementoConsent" : "", "websiteConsent" : "", "promoConsent" : "", "signoutConsent" : "", "signout1" : "", "signout2" : "", "signout3" : "", "guardian" : "XXCw56bLosgswzgmy" }
Screen shot:
Any help/clarification/things to try would be greatly appreciated.
Thanks!