profile image

L o a d i n g . . .

insertMany: 배열을 받고 리턴으로 프로미스를 반환한다. 한번에 대량 DB를 삽입할 때 사용할 수 있으며 이 메서드를 사용시 따로 save()메서드를 쓰지 않아도 된다.
 

Movie.insertMany([
  {
    title: 'Amadeus',
    year: 1986,
    score: 9.2,
    rating: 'R',
  },
  {
    title: 'Alian',
    year: 1979,
    score: 8.1,
    rating: 'R',
  },
  {
    title: 'The Iron Giant',
    year: 1999,
    score: 7.5,
    rating: 'PG',
  },
  {
    title: 'Stand By Me',
    year: 1986,
    score: 8.6,
    rating: 'R',
  },
])
  .then((data) => {
    console.log('데이터 삽입 성공!');
    console.log('--------------------');
    console.log(data);
  })
  .catch((err) => console.log(err));

 
 

 
 
 
몽고 디비에도 잘 들어왔는지 확인해보자
몽고디비 쉘에서

db.movies.find()

 

 

반응형
복사했습니다!