javascriptreact-nativeparse-serverback4app

Back4app Parse Server Retrieved ObjectId


hi i wonder why i cannot retrieve an objectId from this json object even i can printout the stringify on console.

I can retrieve all other column with no problem but not objectId. It happen to all table in my back4app Parse server.

i need the objectId in order to update certain column in my program

below is my code

1)

   const parseQuery = new Parse.Query("User");
    parseQuery.equalTo("username", "Azha");
    let queryResult = await parseQuery
      .find()
      .then((results) => {
        results.forEach((prod) => {
//if i change below to prod.get("objectId") error undefined appear
          console.log("Product ID Available : " + prod.get("username"));
     
        });
      })
      .catch((error) => {
        console.log(error);
      });

    const parseQuery = new Parse.Query("User");
    parseQuery.equalTo("username", "Azha");
    try {
      let todos = await parseQuery.find();
      if (todos.length > 0) {
//if i change below to todos[0].get("objectId") error undefined appear
        console.log("yes Approval : " + todos[0].get("companyname"));
      } else {
        console.log("No Approval");
      }
      console.log("- value is : " + JSON.stringify(todos));
      console.log("----------------------");  
    } catch (error) {
  
      Alert.alert("Error!", error.message);
     
    }

below is the json printout

[{"sessionToken":"r:d9166aa9d7143463c46725d095b53946","username":"Azha","createdAt":"2021-09-21T15:27:01.088Z","updatedAt":"2021-10-10T13:01:27.126Z","companyname":"XXX","fullname":"XXX","email":"azha@abc.com.my","emailVerified":true,"accesslevel":"Maintenence","companydivision":"Maintenence","position":"Technician","phonenumber":"999","userteam":"B","useremail":"azha@abc.com.my","ACL":{"*":{"read":true},"IuBGmCtxyu":{"read":true,"write":true}},"objectId":"IuBGmCtxyu"}]


Solution

  • Yes i just found my solution. Using object1 below:

       const parseQuery = new Parse.Query("User");
        parseQuery.equalTo("username", "Azha");
    
        try {
          let todos = await parseQuery.find();
          var object1 = JSON.parse(JSON.stringify(todos));
      
          console.log("2- value is : " + object1[0].objectId);
    
        
        } catch (error) {
    
          Alert.alert("Error!", error.message);
     
        }