Can you query.equalto the same value of the pointer?

const createNewComment = async (e, content) => {

        e.preventDefault()

        const Posts = Moralis.Object.extend("Comments");

        const query = await new Moralis.Query(Posts);

        query.equalTo(post.title, resultId);

        const x = await query.first();

        const newComment = Moralis.Object.extend("Comments");

        const comment = new newComment();

        comment.set("content", content);

        comment.set("author", Moralis.User.current());

        comment.set("post", x);

        comment.save();

    console.log(comment)

      }

Can you query.equalto the value of a pointer? So in my database I have a pointer with the posts that corresponds to the comment and I want to render all those that equalto the id of the post. Is that possible?

it should be possible

not sure if this helps: https://stackoverflow.com/questions/26923172/query-on-pointer-in-parse-com-objects-in-javascript

useEffect(async () => {

    const Comments = Moralis.Object.extend("Comments");

const query = await new Moralis.Query(Comments);

const object = await query.find({

    function(results) {

        var userPointer = {

            __type: "Pointer",

            title: results.resultId

        }

        query.equalTo("post", userPointer);

        query.find({

            success: function(results) {

                console.log(results)

        },

        error: function() {

            console.log("Error");

        }

        })

    },

});

so would this find the title of the post query? but it finds me all the comments

it looks like you run query.find once, where it will find all the comments
what you want to do after that?

want to search inside the comments for the pointer ā€œpostā€ and inside the pointer post, find the title that it matches with the current slug which is the title of the post

I think that you can include that post object in the original query, with query.select and query.include so that you can access it directly

something like in this post: [SOLVED] Receiving empty array of results when trying to fetch data from the user table

okay so like this i get all the posts:

useEffect(async () => {

    const Comments = Moralis.Object.extend("Comments");

const query = await new Moralis.Query(Comments);

query.include("post");
query.equalTo("title", resultId)

const middleresult = await query.find();

const results = JSON.stringify(middleresult, null, 2)

const finalResult = JSON.parse(results)

console.log(finalResult)

for (let i = 0; i < middleresult.length; i++) {

    // This does not require a network access.

    const post = middleresult[i].get("post");

    console.log(post)

  }

}, )

But how would you make it so that it only renders the ones that matches the title of the post? Iā€™ve tried with query.equalTo("title", resultId) where resultId is the name of the post. But this doesnā€™t get me the results as it just renders an empty array.

I donā€™t understand what is resultId, and the title is from Comments table accessible directly?
you may have to use something like query.equalTo("post.title", title_post)

okay iā€™ve tried this and it works up until the query, because the query doesnā€™t get stringified. What can that be due to? When I console log the finalresult it just appears an empty array. But when I console log the query, it appears the values

useEffect(async () => {

    const Comments = Moralis.Object.extend("Comments");

const query = await new Moralis.Query(Comments);

query.equalTo("post.title", resultId);

console.log(query)

const middleresult = await query.find();

const results = JSON.stringify(middleresult, null, 2)

const finalResult = JSON.parse(results)

console.log(finalResult)

}, [data])

you can try to comment this line to see if you get all the comments, maybe that equalTo doesnā€™t work yet (it could be from the value of resultId, or maybe is not accessible with post.title)

Iā€™m not sure what you expect to get with this console.log, the query is not executed yet.

you can add directly after this line a console.log(JSON.stringify(middleresult)) without the need for the next two lines

I do get the values in

query.equalTo("post.title", resultId);

but later on, when I console log the stringify values I no longer get the values. I get an empty array

on what values are you referring?

the comments that correspond with the title of post.title

But I get them like this:

I think that it is only the query information, without any data yet.

so ā€œpost.titleā€ doesnā€™t work right?

or what you have in that resultId could not match anything
you can try without that line to see if you get all the results, add an query.include(ā€œpostā€) to see how the data looks like and after that to try again by adding that query.equalTo

yes, I do get the vallues without that line, but resultId in theory is the title of the post, you know?

I know that it should be the title of the post, but I donā€™t know exactly what you had in that variable name

if you get the values without that line, then you have to see what is not working well with that query.equalTo line

what i donā€™t understand is why this finding me the comments query but it is not finding it with the post pointer:

so the console log outputs me all the query, but without the posts

useEffect(async () => {

    const Comments = Moralis.Object.extend("Comments");

const query = await new Moralis.Query(Comments);

const middleresult = await query.find();

console.log(JSON.stringify(middleresult))

}, [data])