Mark deletion on custom fields I am using mongodb as the backend for the node_save functionality and I have migrated my custom fields. So for every node save it calls the hook_field_storage_write() . Thus the data is saved in the mysql and then calls the mongodb implementation. This hook inserts the document in mongodb and calls the mongodb_migrate_write_helper. In the function the migrated fields are set with the value of deleted column as 2.

Thus if I have migrated a field 'field_email' from mysql to mongodb the mongodb_migrate_write_helper sets the field_email for the entity as deleted = 2. What does the deleted flag do? Are the rows marked as deleted = 2 deleted in a specific point of time or by some hook calls? . I have seen in many instances in the core modules where deleted is set as 1. Are there any purge scripts that are run at specific points of time for deletion of fields marked as deleted.

function mongodb_migrate_write_helper($entity_type, $entity_id) {
  $migrate_fields = variable_get('mongodb_migrate_fields', array()); // Migrated field names are stored in variable.
  foreach ($migrate_fields as $field_name =&gt; $v) {
    $field = field_info_field($field_name);    
    db_update(_field_sql_storage_tablename($field))
      -&gt;fields(array('deleted' =&gt; 2))
      -&gt;condition('entity_type', $entity_type)
      -&gt;condition('entity_id', $entity_id)
      -&gt;execute();
    }
}
The deleted column in a field table is:


  A boolean indicating whether this data item has been deleted


Therefore the only valid values are 0 and 1. Or, at least, 0 == false, and anything else is equivalent, and == true.

You'd need to ask the module developers for their motivation to be 100% sure why they're bucking the trend there and using '2' instead, but maybe it's some sort of hack to exclude certain records from being queried with WHERE deleted = 1, but still available for WHERE deleted &gt; 0. Not sure though, that's just a guess.

As for what it does: it simply marks a record as deleted, so it won't be included in query results, and can be moved into a deleted data table, from which it's subsequently removed on cron runs.