Was there any resolution to this issue? I have the exact same problem - my server module just does not seem to enter the wixdata.query.find code at all:
import wixData from ‘wix-data’;
export function init()
{
console.log(‘A’);
wixData.query(‘Courses’)
.find()
.then((results) => {
console.log(‘B’); return results.items.length;
})
. catch ((err) => {
console.log(‘error’); return err;
});
}
console will log ‘A’, but not ‘B’ or ‘C’. It doesn’t make sense. This code works fine when it is in the front end.
Thanks for the update Yafim. I actually managed to get the server code to access and return a collection in the end - I’m not 100% sure what made it work, but note the use of “async” and "await. Eventually it worked:
Server module:
import wixData from 'wix-data';
export async function getUniqueValues(returnColumn, filters) {
let query = wixData.query('Courses');
filters.forEach(function (filter) {
query = query.eq(filter.field, filter.value)
});
let results = await query.find();
return getUniqueColumnValues(results.items, returnColumn);
}
function getUniqueColumnValues(items, returnColumn) {
var returnColumnValues = items.map(item => item[returnColumn]);
return [...new Set(returnColumnValues)];
}
Front-end:
import {getUniqueValues} from 'backend/serverModule';
import { fetch } from 'wix-fetch';
import wixData from 'wix-data';
export async function getData() {
const apiKey = "xxxxxxxxxxxxxxxxx";
//const id = "xxxxxxxxxxxxxxxx"; (it works when i declare this but i want to take values from my database)
let id = wixData.get('myDatabaseName'.'title');
const response = await fetch("https://www.exampleapis.com/&id=" + id + "&key=" + apiKey, {
method: 'get'
});
Actually getData() returns a url which show the statistics of website but here i want to take stored values from my wix database in let id that means my backend code connected to my database field which call in front end, My code is running successfully when i declare one value like: const id = ‘xxxxxx’ but i want to take the values from database, i hope you understand