Merger of binary neutron stars and black hole-neutron star binaries is the promising source of short-hard gamma-ray bursts, the most promising site for the r-process nucleosynthesis, and the source of kilonovae. To theoretically predict the merger and mass ejection processes and resulting electromagnetic emission, numerical simulation in full general relativity (numerical relativity) is the unique approach. We summarize our current understanding for the processes of neutron-star mergers and subsequent mass ejection based on the results of long-term numerical-relativity simulations. We pay particular attention to the electron fraction of the ejecta.