'How to query a document mongodb and react

I wonder why this is not working…

This function should return true if there are any documents that match query.

Thing I want to do is if the frequency is one time, just want to set query with creatorDetails.uuid and measureId to find()

The structure is useTracker in client side call hasCompelted on server side (survey collection) and this function also call hasCompleted on other server side file which is measure collection.

the client side

  const hasCompleted = useTracker(
    () => survey.hasCompleted(Meteor.myFunctions.getCurrentUserId()), // this
    [JSON.stringify(survey)],
  )

the server side (survey)

  hasCompleted(userId) {
    const questionIds = this.questions.map(question => question._id);
    const measures = Measures.find({questionId: {$in: questionIds}});

    switch (this.frequency) {
      case Frequency.ONE_TIME:  {
        return measures.fetch().every(measure => {
          measure.hasCompleted(userId); // this
        });
      }
    }
  },

This is also the server side (measure)

  hasCompleted(userId) {
     // ....
    const query = {
      'creatorDetails.uuid': userId,
      measureId: this._id,
    };

    if (this.typeOptions.frequency === Frequency.ONE_TIME) {
      return query;
    }
    // ....
    console.log(query);
    return MeasureData.find(query).count() > 0;
}

query console.log

{
  creatorDetails.uuid: "wD7BaeY6SsNSBgjbg"
  measureId: "GFKdwrmwkZ6FkAsco"
}

Now I’m looking on studio 3t and there is a document matching this

db.getCollection("MeasureData").find({
    "creatorDetails.uuid" : "wD7BaeY6SsNSBgjbg", 
        "measureId": "GFKdwrmwkZ6FkAsco",
})

but this hasCompleted() still returns false…



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source