populating nid in a custom field
I guess I found a solution for this problem:

function mymodule_node_insert($node) {
  $node-&gt;field_custom_field['und'][0]['nid'] = $node-&gt;nid;
  node_save($node)
}


I saved the changes to database with node_save()