score:1
First, you shouldn't use findOne
in your publication - publications should return a cursor; in this case you will be publishing a single-document cursor (as long as only a single document in Groups matches the query). Just use find
in the publication.
Second, when you're fetching the data on the client, you should make your query appropriately specific. Currently you're fetching all groups to which your client is subscribed (presumably you have other publications and subscriptions running.) See here for the Meteor Guide's advice. You'll want to do something like this in your container:
return {
group: Groups.findOne({
code: Meteor.users.findOne(this.userId).profile.selectedGroup
})
}
Finally, if your user's selectedGroup can change, you should be aware that the data that publications provide can change, but their queries can't. So if your user's selectedGroup changes, the publication won't reflect this - as its query won't change. See here. So you will want to use the reactive publish package to deal with this.
Source: stackoverflow.com
Related Query
- A Meteor publication or subscription returns an array of objects when it should return just one object
- Object is not extensible error when creating new attribute for array of objects
- React: Updating state when state is an array of objects
- ReactJS: Should a large array of objects be passed down to many levels of child components as props?
- React State update a nested array with objects based on the id when iterated
- Typescript - failure to update array of objects when using date
- Lost input focus when trying to update an array of objects in React Hooks
- React: Each child in an array or iterator should have a unique "key" prop when Mapping custom components
- How to re-render react component when mapping over state that is array of objects
- React functional component - how do I pass refs back to parent when component returns an array of elements?
- An error comes when mapping array of objects in React
- How to update specific value when the state is an array of objects - React
- Mirroring the position when moving objects from the array to the array to another object in React
- Keycloak object property "authenticated" returns false when should be true
- TypeError when making Columns for React-Table using array of objects as Data
- Compare current to previous when mapping array of objects onto html elements
- What should I do to render sum of array objects values from API call
- Objects are not valid as a React child when setState of an array at the end of a promise chain
- Where should I put the Meteor subscription in a tracker-react container?
- Typescript object possibly undefined when looking for objects inside an array
- Filtering away javascript objects into an array when using fetch
- How can I make useEffect not return the initial value? I keep getting empty array when I'm trying to pass an array of objects into a component
- How to return objects that have matching value when comparing to a separate array
- Create a unique key when mapping over array of objects
- ReactJs Redux: how to remove duplicate objects (with duplicate values) from an array when deciding redux state (after map, filter, etc. functions)?
- how to update array of objects when input is changed
- How to set the state when it is an array of objects
- What should be the type of function which returns array of Promises
- How to update a useState which has an array, inside this array I have objects this objects will update when the input value will change in react js
- React.js Pane seems to crash when an Array of Objects is added to hook
More Query from same tag
- How to render dynamic React component from object
- React communication problem from child to parent
- not able to extract variables from given sample
- React Context API, set context state from Child Components instead of passing functions as props
- useState in a createHigherOrderComponent
- "This express is not callable. Type 'Boolean' has no call signatures"
- Reroute user if conditions are met
- Conditional show/hide for react radio button in .map
- error: Property undefined while fetching data using API
- How to rerender, if key stays the same, but other values change?
- Update state props without firing a dispatch() - React Redux
- React project firebase deploy showing welcome screen
- How to return an event from Button using react-bootstrap?
- How to properly use and move between react routers?
- How to enable source maps in create-react-app?
- Not able to perform PUT request in my react js application
- Cannot find module 'babel-core' and "@babel-core" is installed
- How to get a custom week value from a WeekPicker in a Form when I submit it
- trouble in npm start due to ELIFECYCLE
- Can I give an Ant Design Icon a custom URL?
- React - beforeunload event on window does not fire
- React Router rendering blank page
- handle useReducer if pass from props
- React-Redux app: How to make that in this field on my page only some part of data displayed?
- Can I use variables as data storage in React? Instead of Redux / Local Storage?
- Why is there no binding between React.Js template and Angular model?
- How to call event target inside a function with enzyme - React
- Value of Select Tag from state dom is not changing in react
- How to properly create and render functional components?
- How to push React component to an array?