0

I want to convert linux date into mongodb timestamp

TODAY= date '+%Y-%m-%d%H:%M:%S' into this $date:"2023-04-09T16:27:54.282Z"

So I can use same date in my dump query

First I want to get yesterday date (todays date minus one day)

TODAY= date '+%Y-%m-%d%H:%M:%S'

YESTERDAY= date +'%Y-%m-%d%H:%M:%S' - 3600 * 1000 * 24

till here I am getting results

Next I want to get YESTERDAY date to be converted into mongodb timestamp, it should be display like below..

$date:"2023-04-09T16:27:54.282Z"

So I can use same date in my dump query

mongodump --host "dba_rs/mongoexample.net:27018"  -u root -p **** --authenticationDatabase admin -d local -c oplog.rs   --query='{"wall":{"$gte":{"$date":"2023-04-10T16:27:54.000Z"} }}' --out /mongologs
Noel
  • 10,152
  • 30
  • 45
  • 67
  • 1
    Please format your code as code blocks or inline code. To show a short piece of code embedded in a line of text, enclose the code in single backticks. To show a line of code or multiple lines, insert a line with 3 backticks (or 3 tilde `~~~`) as separate lines before and after the code block. Do you mean somenthing like `date '+%FT%T.%3NZ' -d yesterday`? – Bodo Apr 11 '23 at 18:09
  • Please review your code snippets ... the first one will output a date, but never assigns a value to the variable. The second gives an error message. And as Bodo said: format your code, please. – tink Apr 11 '23 at 18:39
  • And *this* is what you want (I think): `YESTERDAY=$(date +'$date:"%Y-%m-%dT%H:%M:%S.000Z"' -d$(date +'yesterday'))` ... try that, followed by an `echo $YESTERDAY` ... P.S.: Using uppercase variable names for bash variables is a bad idea, there's a good chance that you accidentally overwrite something system-specific. – tink Apr 11 '23 at 19:59

0 Answers0