wixData.get() returning null value

// For full API documentation, including code examples, visit http://wix.to/94BuAAs

import wixData from ‘wix-data’;

let options = {
“suppressAuth”: true ,
“suppressHooks”: true
};

wixData.get(“TestCol”, “CA”)
.then( (results) => {
let item = results; //see item below
console.log(item);
} )
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
} );

Loading the code for the TestPage page. To debug this code, open qbdi8.js in Developer Tools.
null

I am new to Wix code. What am I doing wrong?

Hi!

From reference:

 function get(collectionName: String, itemId: String, [options:WixDataOptions]): Promise<Object> 

Get function need id of the element which you want to get (as second parameter)
You can see it in collection (vivible fields => turn on “id” field, it’s hidden by default)

If you just want to get some item from collection based on some condition, it’s better to use query -

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    let firstItem = results.items[0]; //see item below
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

/*  firstItem is:
 *
 *  {
 *    "_id":          "00001",
 *    "_owner":       "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
 *    "_createdDate": "2017-05-24T12:33:18.938Z",
 *    "_updatedDate": "2017-05-24T12:33:18.938Z",
 *    "title":        "Mr.",
 *    "first_name":   "John",
 *    "last_name":    "Doe"
 *  }
 */

Thank you! That was so dumb of me. Have been making assumptions based on how other languages work.

I have another issue now. Spent hours. I had it working in both preview and publish mode but it stopped working in publish mode and not sure what i did. I know it has to be something simple.

The dropdown for genders is not working…not dropping down. Any common mistakes people make? I changed all the permissions to Anyone just to eliminate that as a cause.

Hi,
Common mistake: CMS: Syncing Content Between Sandbox and Live Collections | Help Center | Wix.com
Roi.

Wow. Talk about yet another rookie mistake… Thank you again bunches. Feel like a total dunce.