WixData.query does not work. Urgent help required

I have created router for my site. In the router, I am trying to query my dataset in router.js file. This is not working. Please help.

Hi Srinivasa,
a router is a backend construct. it is a piece of code that allows you to decide, based on the incoming URL, which page needs to be displayed.

a dataset is a frontend construct. it is aimed at helping you retrieve data from a collection, and populating your visual elements on the page.

so, as you can understand, the two don’t mix.

I suggest you read this: Velo: Creating a Router | Help Center | Wix.com

it should provide some more clarity about routers, their purpose and how to build them.

good luck!

Thanks alot for the reply.
I guess I spelled it wrong. I mean database collection and not dataset.

I have done this in my code

wixData.query(“Data”).eq(“Cate”,“Basic”).find().then( (peopleData) => {
res = peopleData;
})

“Data” is a file under Database which is a sheet in Wix.

Even the console.log does not print logs in developer tools after I publish the site.

Hi, when using code to query for data, you need to use the field keys, not their display names.
You can find the field key by selecting the collection (for example, “Data”) and opening the field properties for the desired field. I’m guessing in your case it will be “cate”.

Example from my collection, notice the field display name is “Test Field” and the field key is “testField”:

Thanks for the reply Tom. I have updated the code. This still does not work. Please find my code below

//Read Our Wix Router API here http://wix.to/94BuAAs/wix-router.html
//import {getData} from ‘Public/getReq.js’;
import wixData from ‘wix-data’;

import {ok, notFound, WixRouterSitemapEntry} from “wix-router”;
let res = {};

export function route_Router(request) {
let data=“”;
const name = request.path[0];

wixData.query(“Data”).eq(“cate”,“Basic”).find().then( (peopleData) => {
data = peopleData.items[0];

if (data) {

   // Define SEO tags  
   const seoData = {  
	   title: data.title,  
	   description: "This is a description of " + data.title + " page", 
	   noIndex: false, 
	   metaTags: { 
	      "og:title": data.title, 
	      "og:image": data.image 
	   } 
   }; 

   // Render item page  
   return ok("route-page", data, seoData);  

}
});
// Return 404 if item is not found
return notFound();

} 

export function route_SiteMap(sitemapRequest) {

// Convert the data to site map entries
const siteMapEntries = Object.keys(res).map((name)=>{
const data= res[name];
const entry = new WixRouterSitemapEntry(name);
entry.pageName = “route-page”; // The name of the page in the Wix editor to render
entry.url = “/route/” + name ; // Relative URL of the page
entry.title = data.title; // For better SEO - Help Google
return entry;
});

// Return the site map entries 
return siteMapEntries; 

}

You need a return statement before calling wix data:
“return wixData.query…”

Will that take us to route-page ? I have tried to putting a return statement for the above code. It does not work. It gives me time out page

Hi. I have moved the wid data logic to the page code where we use $w. I am able to to get the data. I have a list of objects. I want to put specific fields in a a grid or repeater.

Following is the code.

// For full API documentation, including code examples, visit http://wix.to/94BuAAs
//import {fetch} from ‘wix-fetch’;
import wixData from ‘wix-data’;

import wixWindow from ‘wix-window’;

$w.onReady(function () {
//TODO: write your page related code here…

 let data = wixWindow.getRouterData(); 

wixData.query(“Data”)
.eq(“cate”,data)
.find()
.then((results) => {
let filteredResults = results.items;
console.log(filteredResults);

    $w("#repeater1").data = filteredResults.item[0].title; 
    $w("#text28").text = filteredResults.item[0].title; 

}
);

#repeater1 is my grid name and #text28 is part of grid where I wanted the title in list of items to be placed. I can see the results in log. Please help

});