Fixed issue with $document bening an array ref not an object

The $document appears as if it is meant to be an array ref but on this line is us used as a object, the fix is a best guess at what is meant to happen.