1

When running the following MongoId query

Project.any_of(
  { completed_at: nil}, { :completed_at.gte => @start_date}
)

it produces this error:

"This method is not prepared to handle key being a Key and serializer being not nil"

I found the validation code for this here but I don't understand what it means.

Using .where( "$or" => [ produces the same error.

MongoId v7.1.5, Rails v6.0, MongoDB 4.4.x

MegaTux
  • 1,591
  • 21
  • 26
  • 1
    Try `where(completed_at: nil).or(:completed_at.gte => @start_date)` – Stefan Dec 16 '20 at 14:34
  • 1
    There wasn't a test case covering this combination and thus it was left unimplemented. What is in `@start_date`? – D. SM Dec 17 '20 at 00:45
  • @start_date is a Date instance. Also, before this filter condition there is another one with an end_date and a scope applied that works on this attributes, too but the smaller query that produces the error is "Project.any_of ..." and the filter I posted above. – MegaTux Dec 17 '20 at 13:36
  • @Stefan that seems to work, thx! – MegaTux Dec 17 '20 at 13:48
  • @D.SM BTW, this query was working on a very old mongoid version, 3.1.4, and in the migration process to v71.5 I saw the error – MegaTux Dec 17 '20 at 13:50

2 Answers2

0

The generic string for this to be like this :

criteria.any_of({ :field1 => "value" }, { :field2 => "value2" })

Dileephell
  • 620
  • 2
  • 7
  • 18
0

This is an issue in Mongoid..

D. SM
  • 13,584
  • 3
  • 12
  • 21