dreamfactorysoftware / df-mongodb

The DreamFactory MongoDB service.
Other
4 stars 7 forks source link

Error on filter $date #4

Open abalad opened 7 years ago

abalad commented 7 years ago

I'm trying to do a query in a MongoDB database with date values but the following situation is occurring:

Filtering with date only goes all normal. Filter: filter:{"$and":[ {"dt_evento":{"$date":"2016-11-28T23:21:43.0000"}} ]}

Filtering with Data + ID Filter: filter:{"$and":[ {"dt_evento":{"$date":"2016-11-28T23:21:43.0000"}},{"bem_id": "58338261bab1178e0a393cec"} []}]

unknow operadtor $and

http://community.dreamfactory.com/t/serious-bug-filter-date-operator-and-on-mongodb/3477

svensteudter commented 7 years ago

Hi,

quite some time ago. But I had the same issue and it was not resolved almost 1 year later and multiple versiosn later.

This "bug" is located in multiple versions always at the same location in src/Resources/Table.php in "function toMongoObjects($record)" is the if clause " if (1 === count($data)) {" limiting the loop to be run at most once, so if a $date object in an array is submitted the date is not converted to MongoDate.

Fixing this is easy: Just remove the "if (1 === count($data)) {" and one of closing brackets. This also works for already installed DF instances by modifying in vendor/dreamfactory/df-mongodb/src/Resources/Table.php.

abalad commented 7 years ago

Thank you @svensteudter, I really did it at that time. And I opened that issue before I fixed the problem, then forgot to send the fix.