AppDB Query giving inconsistent results

sourabh05
sourabh05 Member
edited June 12 in APIs & Domo Developer

My AppDB query gives the correct result first time when I search a document but the very next query for that same document results nothing. And every subsequent query for that document results nothing.

This is a pattern every time I try searching a different document in AppDB.

  //check if the document already exist 

const appDBQuery = `{    "content.ac_page_id":      {        "$eq": ${pageID}      }  }`;

const existingPageAC = await domo.post(`/domo/datastores/v1/collections/${collectionAlias}/documents/query`, appDBQuery)

image.png

any troubleshooting suggestions?

Best Answer

  • ArborRose
    ArborRose Coach
    edited June 13 Answer ✓

    Your code looks like its sending JSON as a string rather than sending as JSON. This might work once, but then fail if it can't be properly parsed as JSON.

    This

    const appDBQuery = `{ "content.ac_page_id": { "$eq": ${pageID} } }`;

    appears to create a string. Try it as

    const appDBQuery = {
    "content.ac_page_id": {
    "$eq": pageID // if pageID is a string, make sure it's already quoted
    }
    };

    const existingPageAC = await domo.post(
    `/domo/datastores/v1/collections/${collectionAlias}/documents/query`,
    appDBQuery
    );


    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

Answers

  • ArborRose
    ArborRose Coach
    edited June 13 Answer ✓

    Your code looks like its sending JSON as a string rather than sending as JSON. This might work once, but then fail if it can't be properly parsed as JSON.

    This

    const appDBQuery = `{ "content.ac_page_id": { "$eq": ${pageID} } }`;

    appears to create a string. Try it as

    const appDBQuery = {
    "content.ac_page_id": {
    "$eq": pageID // if pageID is a string, make sure it's already quoted
    }
    };

    const existingPageAC = await domo.post(
    `/domo/datastores/v1/collections/${collectionAlias}/documents/query`,
    appDBQuery
    );


    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • Thanks, @arborRose. So the JSON format is not working for me. But your inline comment about making sure the page ID is in quotes did the trick.

     const appDBQuery = `{    "content.ac_page_id":      {        "$eq": "${pageID}"      }  }`;

    Although, I remember there were times that even this query was giving inconsistent results but I may try this out for now until I figure out how to make the JSON format work.