Fix a bug: truncate generated fields.

When an indexed field (like the customFields) has a too large value (less than 1024 bytes)
the document is not inserted (at least with MongoDB 2.6).