datanoise / mongo.cr

Crystal binding for MongoDB C Driver
MIT License
97 stars 35 forks source link

Date Range Query #63

Open marcstein opened 4 years ago

marcstein commented 4 years ago

When trying to execute the following query

{ $and: [ { "created_at": { $gte: ISODate("2020-05-01T00:00:00.000+0000") } }, { "created_at": { $lt: ISODate("2020-06-01T00:00:00.000+0000") } } ] }

I've tried

collection.find{ $and: [ { "created_at": { $gte: ISODate("2020-05-01T00:00:00.000+0000") } }, { "created_at": { $lt: ISODate("2020-06-01T00:00:00.000+0000") } } ] }.each do |doc| docs << doc p doc end

This generates the following error

Error: $global_variables are not supported, use @@class_variables instead

I've tried quoting the globals, e.g..

collection.find{ "$and": [ { "created_at": { "$gte": ISODate("2020-05-01T00:00:00.000+0000") } }, { "created_at": { "$lt": ISODate("2020-06-01T00:00:00.000+0000") } } ] }.each do |doc| docs << doc p doc end

This generates

Error: unexpected token: :

Any suggestions?

Many thanks!