How to get a result of a Parse Server Query

How can I get the values of the searched objects?

const query = new Parse.Query(Parse.User);
      query.equalTo("sexo", "feminino");
      query
        .find()
        .then(results => {
          console.log(results.get("username"));
        })
        .catch(error => {
          console.log(error);
        });

TypeError: "results.get is not a function"

Upvotes: 0

Views: 3275

Answers (1)

Julien Kode
Julien Kode

Reputation: 5479

How to get values of a search query in Parse server ?

Query.find will be able to fetch the results of your queries. As you can have multiples results, the object that you get is an array of elements

so if you want to display the name of all users of your query you'll have to iterate to display all of your users.

const query = new Parse.Query(Parse.User);
query.equalTo("sexo", "feminino");
query
    .find()
    .then(results => {
        results.forEach(user => {
            console.log(user.get("username"))
        });
    })
    .catch(error => {
        console.log(error);
    });

If you want to have examples of queries click here

Hope my answer help you 😊

Upvotes: 2

Related Questions