Items Being Removed from Collection


#1

Would appreciate any help on this as I’m very new to Meteor!

I’ve set up a simple PUB and SUB. On initial load after logging in, the following occurs where the application unsubscribes to the collection:

However on a refresh of the page, everything works fine after.

I’ve not written anything to unsubscribe to the collection. Apart from the above issue, my data seems to be rendering reactively (from my untrained eye). Any help would be appreciated, thank you!


#2

We can’t help with only this information.


#3

Oh sorry, let me provide you where I’ve run the SUB and PUB.

I’m using React with Redux, so my SUB is in my actions.

function findBoardAll(userId) {
	return async function(dispatch) {
		dispatch({
			type: 'REMOVE_STATE',
			payload: {}
		})

		Meteor.subscribe('boards', [userId], {
            onReady: () => {
                console.log('ready')
            },
            onStop(err) {
                console.log('stop', err)
            }
        })

		Tracker.autorun(() => {
			const boardData = Boards.find().fetch()
			const boards = {}
			boardData.forEach((board) => {
				boards[board._id] = {
					_id: board._id,
					title: board.title
				}
			})

			dispatch({
				type: 'FIND_BOARD_ALL',
				payload: boards
			})
		})
	}
}

This is my PUB

if (Meteor.isServer) {
	Meteor.publish('boards', (userId) => {
		return Boards.find({ users: userId })
	})
}

#4

I don’t know why you are using an function that returns an async function. My recommendation is to read up on this in the meteor guide


#5

I’ve investigated further and determined that I am unable to subscribe immediately after a login unless I do a refresh of the page.

On my React component I run a redux action on componentDidMount()

componentDidMount() {
		const { boardActions } = this.props
		boardActions.findBoardAll(Meteor.userId())
	}

Redux Action

function findBoardAll(userId) {
	return async function(dispatch) {
		Tracker.autorun(() => {
			console.log(Meteor.subscribe('boards', userId).ready())
		})		
	}
}

The action then attempts to subscribe to ‘boards’. I’m using an async function because of redux-thunk where I supposedly dispatch a payload after receiving data from the subscription

In my server

if (Meteor.isServer) {
	Meteor.publish('boards', function (userId) {
		if (!this.userId) {
			console.log(`Failed to Publish`)
			return []
		} else {
			console.log(`Publish Success`)
			return Boards.find({ users: userId })
		}
	})
}

I am successfully publishing immediately after a login, but I cannot get the subscription to return “true” in Tracker.autorun() unless I do a refresh of the page where I then see the “false” followed by a “true”.