A retired San Diego public schoolteacher and counselor will serve 7 years in federal prison for collecting nearly a million images of child pornography.

James Rick Mitchell, of San Diego, taught in city schools for 34 years. He must surrender to prison by Feb. 7, 2014, the U.S. Attorney's Office said in a statement announcing his sentence.

"According to documents filed in court, Mitchell collected 947,542 images and 4,751 videos depicting minors engaged in sexually explicit conduct," the U.S. attorney said.

Mitchell spent more than $4,300 for his "trove" of photos, prosecutors said, citing a U.S. Postal Service investigation.

Mitchell worked for the San Diego Unified School District for 34 years, from 1969 to 2003. He taught P.E. and worked as a counselor at Einstein Junior High School, as a math teacher and track coach at Point Loma High School, and worked for 24 years -from 1979 to 2003 - as a math teacher, counselor and track coach at University City High School.