I am using the withQuery of grapher-react (https://github.com/cult-of-coders/grapher-react) to fetch data.
The query is like below
const userData = {
_id: 1,
profile: {
firstName: 1,
lastName: 1,
phoneNumber: 1
},
shortName: 1,
cookies: 1,
}
const tutorUserData = {
_id: 1,
profile: {
headline: 1,
hourlyRate: 1,
firstName: 1,
lastName: 1,
croppedPicture: 1,
tag: 1,
currency: 1,
subjects: 1,
phoneNumber: 1
},
shortName: 1,
cookies: 1,
}
export default Packages.createQuery('packages', {
ownerId: 1,
owner: userData,
creatorId: 1,
creator: tutorUserData,
cost: 1,
createdAt: 1,
expiryDate: 1,
currency: 1,
values: 1,
$filters: {
expiryDate: { $gt: new Date() },
'values.remainingMinutes': { $gt: 0 }
},
$options: {
sort: {
createdAt: -1
}
},
$filter({ filters, options, params }) {
if (params.filters) {
Object.keys(params.filters).forEach(key => {
filters[key] = params.filters[key]
})
}
if (params.options) {
Object.keys(params.options).forEach(key => {
options[key] = params.options[key]
})
}
}
})
The code of withQuery:
withQuery(
({ otherUser, user, params }) => {
return query.clone({
...params,
filters: {
$and: [{ ownerId: user._id }, { creatorId: otherUser._id }]
},
options: {
limit: 3,
sort: { 'values.pending': -1, createdAt: -1 }
}
})
},
{ reactive: true }
)(Component)
And the result of creator data: result
I am sure the creator's profile have many fields other than the result in database.
Does anyone have any ideas about why I the result like that?
Are you denormalizing the user's profile into the
packages
docs, or are you using grapher's collection linking for theowner
andcreator
fields?As this is a reactive query, are you using Scoped Publications? If not, it is possible that you have other publications placing these docs in the client's minimongo already. In such a case, if for some reason the server fails to match and publish the expected docs, the grapher query execution on the client may still find and return the docs in minimongo from the other publications, which may have a different set of published fields. See this similar issue.
Aside, I should point out that Meteor's docs generally recommend that you don't use user.profile.