Hi is there any way to search and get the records in one query instead of 2 quires . I wanna search to survey docs
and get the survey question if a person has not answered the question today. i wanna show survey question once in a day … to do this right now i can do this with two quires but i wanna to this in 1 query if possible.
MY QUERY 1 i am checking in this query that employee 7019 has answser the survey on today . if not answer i am searching for survey for employee 7019 which he has not answer yet in query 2
so i want these two queries in one query if possible thanks
QUERY ONE (checking if answer today)
SELECT survey.* FROM bk_initialization_hq survey WHERE
survey.type = ‘survey_question’
AND ((‘7019’ IN survey.survey_results[].employee_id AND ‘2020-04-19’ IN survey.survey_results[].created_date)
QUERY 2 if not answeer fetching the records
SELECT survey.* FROM bk_initialization_hq survey WHERE survey.branch_type = ‘All Branches’
AND survey.type = ‘survey_question’ AND survey.created_date BETWEEN ‘2020-04-01’ AND ‘2020-04-31’
AND (‘7019’ NOT IN survey.survey_results.employee_id
OR ARRAY_LENGTH(survey.survey_results) = 0) LIMIT 1
My docs
{
“survey_id”: “322120000065”,
“survey_question”: “Where is cadna”,
“option_1”: “op1”,
“option_2”: “op2”,
“option_3”: “op3”,
“option_4”: “”,
“option_5”: “”,
“answer”: “option_1”,
“branch_type”: “All Branches”,
“branches”: [
“3221”
],
“status”: “Active”,
“branch_id”: “3221”,
“created_date”: “2020-04-18”,
“updated_date”: “2020-04-18 21:13:50”,
“survey_results”: [
{
“branch_id”: “3221”,
“employee_id”: “7019”,
“answer”: “op2”,
“created_date”: “2020-04-19”
}
],
“type”: “survey_question”
}
here employee 7019 has answered so it should return null and should not search for any other survey