While I want to fetch data from mongocollection based on updated time in shell I'm facing this error. Where I'm passing the date in other sh file

This is my mongoexport

mongoexport --ssl --sslCAFile $sslCAFile --host $host -u $username -p $password --collection $collectionMember --db $database --limit 5 --query “’./datequery.sh’” --out $output

datequery.sh

start= sort -n /ipath/date.txt | tail -1
end= date --utc "+%FT%T.%3NZ"
echo '{"memberCard.cardMbrDtlsCreatedTms": { "$gte": { "$date": "$start"}, "$lt": {"$date": "$end"}}}'

error validating settings: query ‘[39 46 47 100 97 116 101 113 117 101 114 121 46 115 104 39]’ is not valid JSON: json: cannot unmarshal string into Go value of type map[string]interface {}

Please read Formatting code and log snippets in posts and update the code and command you published.

The way it is formatted it is not clear if the syntax is wrong or simply the formatting.

Welcome to the MongoDB Community @Yugandhar_Prathi !

The --query parameter for mongoexport expects a query as a JSON document enclosed in quotes.

You can use shell command substitution to replace ./datequery.sh with the output of running that command, but the supported syntax is either single backticks (`command`) or $(command).

Currently you have used single quotes (’), which (in a shell context) will preserve the literal value of each character within quotes. The "39 47 … " sequence is ./datequery.sh converted to the decimal value of each character.

Either of these should work assuming ./datequery.sh is executable:

   --query="$(./datequery.sh)"
   --query="`./datequery.sh`"

I think the first form is more readable and consistent with the other variable substitutions using $.

Regards,
Stennie

1 Like

Thanks @Stennie when I ran the job with first mentioned option
I am getting this error
error validating settings: query ‘[50 48 50 50 45 48 49 45 50 49 84 48 48 58 48 48 58 48 48 46 48 48 49 90 10 50 48 50 50 45 48 57 45 48 57 84 48 55 58 50 53 58 49 54 46 55 52 48 90 10 123 34 109 101 109 98 101 114 67 97 114 100 46 99 97 114 100 77 98 114 68 116 108 115 67 114 101 97 116 101 100 84 109 115 34 58 32 123 32 34 36 103 116 101 34 58 32 123 32 34 36 100 97 116 101 34 58 32 34 36 115 116 97 114 116 34 125 44 32 34 36 108 116 34 58 32 123 34 36 100 97 116 101 34 58 32 34 36 101 110 100 34 125 125 125]’ is not valid JSON: invalid character ‘-’ after top-level value

I changed my entire shell script and passing query
source /path/config.sh

start_dt= sort -n /path/date.txt | tail -1

end_dt= date --utc “+%FT%T.%3NZ”

mongoexport --ssl --sslCAFile $sslCAFile --host $host -u $username -p $password --collection $collectionName --db $database --limit 5 --query ‘{“xxxx.cxxxCreatedTms”: { “$gte”: { “$date”: “$start”}, “$lt”: {"$date": “$end”}}}’ --out $output

While I ran the above script I am facing this error

2022-01-21T00:00:00.001Z
2022-09-09T07:31:18.924Z
2022-09-09T03:31:19.023-0400 error validating settings: parsing time “$start” as “2006-01-02T15:04:05Z07:00”: cannot parse “$start” as “2006”
2022-09-09T03:31:19.023-0400 try ‘mongoexport --help’ for more information

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.