4, got an error saying Uncaught Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
I also checked if activities are subscribed with meteor extension.
And yes I see documents with cardId: _id existing on activities database in Minimongo tab.
const { _id } = card || {}. It is better to cover for situations where card is undefined.
Have a DB index for cardId.
Restrict de returned fields to only the document _id an see if you get all documents in this case.
Run all these on the server side where you only have a server - DB relationship. Would be interesting to see if you get the full result on the server but not on the client.
What I see in db, I’m pretty sure that all of the documents have commentId
But I also removed commentId: {$exists: true} inside query and tried to fetch documents and the result was the same, I got documents back in some case but not all the time.
import { Meteor } from 'meteor/meteor'
import { Activity } from './activitySchema' // this is your DB schema
const uri = Meteor.isProduction ? process.env.MONGO_ACTIVITIES_URL : 'mongodb://127.0.0.1:3001/meteor' // in production you might use multiple DBs (different db URIs). It defaults to your MONGO_URL
const _driver = new MongoInternals.RemoteCollectionDriver(uri, {})
const Activities = new Meteor.Collection('activities', { _driver })
Activities.attachSchema(Activity)
Activities.createIndexAsync({ type: 1, name: 1 }) // you just created (or attached to an existing collection) and declare (create) your indexes.
Activities.deny({
insert: () => true,
update: () => true,
remove: () => true
})
export default Activities
A DB schema may look like this:
// the './activitySchema' file from the import above.
import SimpleSchema from 'simpl-schema'
const Activity = new SimpleSchema({
name: String,
description: { type: String, optional: true },
// .....
})
export { Activity }
Simply put, whatever you query for in a Mongo Collection must be covered by an index or many. You may read here about compound indexes which are what you are going to use more as your DB schema gets more complex and you do more complex queries: https://www.mongodb.com/docs/manual/core/index-compound/