GraphQL error: No matching document found

Error: GraphQL error: No matching document found for id "6068812264169f0c98cc9e9b" version 97 modifiedPaths "comments, comments.0, comments.0.likes"
this my code

async likeReply(_, { postId, commentId, replyId }, context) {
          const { username } = check_auth(context);
          const post = await Post.findById(postId);
          if (post) {
            const comment = post.comments.find((c) => === commentId);
            if (comment) {
              const reply = comment.replies.find((r) => === replyId);
              if (reply) {
                if (!!reply.likes.find((like) => like.username === username)) {
                  reply.likes = reply.likes.filter(
                    (like) => like.username !== username
                } else {
                    createdAt: new Date().toISOString(),
                return post;
              } else throw new UserInputError("Reply not fund");
            } else throw new UserInputError("Comment not fund");
          } else throw new UserInputError("Post not fund");


im working with the latest version
i’m using apollo server #graphql , react js

Hi Dimer!
Thanks so much for your question. I don’t think this is a GraphQL issue though. Do you use Mongoose? I believe findById function requires that postId be of type ObjectId. If this isn’t the case, if postId is a string, try using a simple find function.

Hope this helps.


1 Like

Error: GraphQL error: No matching document found for id “606bd3cf30273a143872d9ac” version 3 modifiedPaths “comments, comments.0, comments.0.replies, comments.0.replies.0, comments.0.replies.0.likes”.

Finally someone respond to me!!, thank you very very much for your response .
YEs i use Mongoose, yes the postId is a type objectID. This happen when a user like a comment real quick , like why the await can’t wait for the first request to finish ?scrnli_4_6_2021_5-35-47 AM

Hi Dimer, so I want to make sure I understand your issue. Can you simplify the function and use findById (posted) successfully without using GraphQL. It returns a document.

Also, you mention this happens when a user likes, and your path is comments.0.replies.0.likes. It looks to be an async/await timing issue. What exactly happens in your application? Can you try some conditional rendering to make sure the “likes” exists/is defined before rendering?


1 Like