This tip is here to remind you that calling a Javascript console.log function without parameters displays results, but not necessarily the results you are looking for. If you want to see the true results of an API, console.log the results explicitly while calling the actual API.
Let's use queryReferenced() to illustrate the point. This function lets you refer to related data in an associated collection. So if I have a collection called courses and another collection called teachers, I can use queryReferenced() to print out a course, including the teacher name and contact information.
While coding, it would be a good first thought to use a simple, empty console.log just to check the results you expect to get, like this:
wixData.queryReferenced("courses", "00023", "teacher")
.then (console.log);
But there are a couple of issues.
Getting more than you bargained for! console.log displays the result of the promise on the console, which includes the underlying structure of the resulting object. You are going to see properties like provider, collectionName, limit, and others. These properties are not returned by the API itself. So don't base your code on the return of these properties.
Getting less than you deserve! console.log does not take getter/setter properties into account. This means that certain information will be missing in the console display if you have any "calculated" properties. A getter "calculated" property could be how many days left before a course starts (calculated using a property called startDate and today's date), or the full name of a teacher (calculated by concatenating the teacher's first name and last name).
Your best bet is to code using the actual API, and be specific and explicit about what you display using console.log. Like this:
wixData.queryReferenced("courses", "00023", "teacher")
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0];
console.log(firstItem);
} else {
console.log("No matching items found.");
}
} )
.catch( (err) => {
let errorMsg = err;
console.log(errorMsg);
} );
Don't settle for less... or more! ... on your console.
BTW - We're locking these posts so that any requests for help with Corvid can be maintained in the Community Discussion section. Please post your questions or feedback there.