0

I have a problem with mongoid

a = Analysis.find('59fadd2bfd52a107d90dadf7')

...

b = a.updated_at.iso8601

=> "2017-11-08T15:16:31+01:00"

Analysis.any_of({:id => '59fadd2bfd52a107d90dadf7', :updated_at => Time.zone.parse(b)}).count

=> 0

Analysis.any_of({:id => '59fadd2bfd52a107d90dadf7', :updated_at => a.updated_at}).count

=> 1

I have tested a lot of things, but i always have 0 count returned

  • Time.zone.parse

  • DateTime.parse

  • Time.parse

And I don't know how to compare that date X_X, the b variable is literally that I'm sending to my api

Community
  • 1
  • 1
  • Why do you need to add an `updated_at` criteria if you have an ID? The id is unique anyways. – max Nov 16 '17 at 18:06
  • The real request is with :updated_at.neq, it's return only the entry who has been updated by someone so i'm need the id and the updated_at to compare – Fabrice Didierjean Nov 16 '17 at 21:46
  • is the field declared as DateTime? – max Nov 16 '17 at 22:16
  • I'm using Mongoid::Timestamps, so from github, it's a Time field maybe it's that. I'll try later with datetime – Fabrice Didierjean Nov 16 '17 at 22:42
  • Stupid question on my part. Of course its Timestamps. Its defined as `field :updated_at, type: Time`. https://github.com/mongoid/mongoid/blob/master/lib/mongoid/timestamps/updated.rb#L14 – max Nov 17 '17 at 00:51
  • The solution is here https://stackoverflow.com/questions/33262792/time-iso-8601-in-ruby, i need the fractional seconds for the comparaison – Fabrice Didierjean Nov 17 '17 at 08:43
  • I was suspepecting it was something like this. I’ll mark it as a duplicate. – max Nov 17 '17 at 09:20

0 Answers0