jamescarr/mongoosastic — pull request #36 by chapel (2012-08-17 20:34:41+00:00)
Title: Fix Bad Mapping in Serialize.js & Preserve Sort Order from ElasticSearch when Hydrating

The existing serialize function convertTypesAsNeeded was causing bad mapping due to closure leaking in the for loop. A simple fix was to grab the keys with Object.keys and wrap it in a forEach loop preserving closure.

The other issue was using sort in ElasticSearch would be clobbered due to MongoDB not returning results in the order given. It is a known issue, and the easy fix was to map the indexes of the original array so it could be reconstructed with the Mongoose documents, preserving the sort order from ElasticSearch