SOLVED : Wix Data Query not Working

this code is returning " data not found " but i have row of order_id with value 23001

import wixData from 'wix-data';
 
  wixData.query("orders")
  .eq("order_id","23001")
  .find()
  .then( (results) => {
    console.log(results);
 if(results.items.length > 0) {
 let firstItem = results.items[0];
      console.log(firstItem);
    } else {
      console.log("no data found");
    }
  } )
  .catch( (err) => {
    console.log(err);
  } );  

but i am having row of 23001 in database

NOTE - Database permission is set to read and write by ANYONE

Firstly, as you have used the first column in your dataset, note that it is locked to title as the field key for it.

You are able to change the field name of that locked column, however the actual field key will always stay set as title.

Also, have you read the eq function info for itf?
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#eq

How is your number stored in the dataset?
It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

1 Like

Hi, Thanks for your reply
the key id for the order_id column is “order_id” only

and i have tried changing data type to text still not working. please help me out

UPDATE - it works. Actually i have change field type to text but still data in the database stored in number datatype . So i clear all the data in database and enter new data and then search it. Taa daa it works
Thanks @givemewhiskey for your help

1 Like

So the dataset field type is set to text now, well note that the user input for the query will be a text element too, so you are now searching using a text box for a text string of a number.

As stated in previous post…

How is your number stored in the dataset?
It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

So previously, your user input of text was trying to find a text string of a number, however your filed type was number so it would not be able to find it.

To change a number to type string so that you can use it with text you can use .toString.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
https://www.w3schools.com/jsref/jsref_tostring_number.asp

To change a type string to number value so that you can use it as a number you can use .parseInt.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
https://www.w3schools.com/jsref/jsref_parseint.asp