Return a null value even if the variable does not exist

So I am trying to return values which may not exists on the document yet. I am getting the following error. If I want to avoid the error should I use If-Exists on each variable that I am returning, or should just return the entire document and do field level check at the client end?

{
    "position": [
      "map",
      "expr",
      "in",
      "object",
      "postAuthorName",
      "from"
    ],
    "code": "value not found",
    "description": "Value not found at path [data,username]."
  }

This is my query

Map(
        Paginate(Documents(Collection('posts')), {size: 1}),
        Lambda(
            "postRefs",
            Let({
              postDoc: Get(Var("postRefs")),
              authorDoc: Get(Select(["data", "postAuthorId"], Var("postDoc"))),
              communityDoc:
              Get(Select(["data", "communityId"], Var("postDoc"))),
            }, {
              postId: Select(["ref", "id"], Var("postDoc")),
              postTitle: Select(["data", "postTitle"], Var("postDoc")),
              postText: Select(["data", "postText"], Var("postDoc")),
              itemPrice: Select(["data", "itemPrice"], Var("postDoc")),
              itemLocation: Select(["data", "itemLocation"], Var("postDoc")),
              imageUrl: Select(["data", "imageUrl"], Var("postDoc")),
              postAuthorId: Select(["ref", "id"], Var("authorDoc")),
              postAuthorName: Select(["data", "username"], Var("authorDoc")),
              postAuthorAvatarUrl:
              Select(["data", "avatarUrl"], Var("authorDoc")),
              communityId: Select(["ref", "id"], Var("communityDoc")),
              communityName: Select(["data", "communityName"], Var("communityDoc")),
            })))

Thank you for approving my post.
I have since gone into the documentation for Select and realized that I could use the default parameter to do this.

BTW, I am working on a Flutter app with Fauna as the backend. I would be coming back with many more queries in the future.

1 Like

No problems! Iā€™m not sure why the AI for the forums flagged your post. And I am glad you figured it out!

Cool! Well, your participation in the forums is welcome, so bring on the questions! :grinning_face_with_smiling_eyes:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.