node.js MongoDB 여러 문서 삽입
여러 문서 삽입
MongoDB의 콜렉션에 여러 문서를 삽입하기 위해이 insertMany()메소드를 사용합니다 .
insertMany()메서드 의 첫 번째 매개 변수는 삽입하려는 데이터가 들어있는 객체의 배열입니다.
또한 오류 또는 삽입 결과로 작업 할 수있는 콜백 함수를 사용합니다.
예
"customers"컬렉션에 여러 문서 삽입 :
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
var myobj = [
{ name: 'John', address: 'Highway 71'},
{ name: 'Peter', address: 'Lowstreet 4'},
{ name: 'Amy', address: 'Apple st 652'},
{ name: 'Hannah', address: 'Mountain 21'},
{ name: 'Michael', address: 'Valley 345'},
{ name: 'Sandy', address: 'Ocean blvd 2'},
{ name: 'Betty', address: 'Green Grass 1'},
{ name: 'Richard', address: 'Sky st 331'},
{ name: 'Susan', address: 'One way 98'},
{ name: 'Vicky', address: 'Yellow Garden 2'},
{ name: 'Ben', address: 'Park Lane 38'},
{ name: 'William', address: 'Central st 954'},
{ name: 'Chuck', address: 'Main Road 989'},
{ name: 'Viola', address: 'Sideway 1633'}
];
dbo.collection("customers").insertMany(myobj, function(err, res) {
if (err) throw err;
console.log("Number of documents inserted: " + res.insertedCount);
db.close();
});
});
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5156 | PHP |
|
2년 전 | 972 | |
| 5155 | JavaScript |
|
2년 전 | 856 | |
| 5154 | PHP |
|
2년 전 | 1769 | |
| 5153 | 웹서버 |
|
2년 전 | 814 | |
| 5152 | PHP |
|
2년 전 | 999 | |
| 5151 | PHP |
|
2년 전 | 859 | |
| 5150 | node.js | 2년 전 | 1292 | ||
| 5149 | OS | 2년 전 | 1524 | ||
| 5148 | 웹서버 | 2년 전 | 922 | ||
| 5147 | PHP | 2년 전 | 6904 | ||
| 5146 | JavaScript | 2년 전 | 1705 | ||
| 5145 | PHP | 2년 전 | 933 | ||
| 5144 | PHP | 2년 전 | 1416 | ||
| 5143 | JavaScript | 2년 전 | 820 | ||
| 5142 | PHP |
|
2년 전 | 910 | |
| 5141 | 웹서버 | 2년 전 | 2409 | ||
| 5140 | 기타 | 2년 전 | 1551 | ||
| 5139 | JavaScript | 2년 전 | 1197 | ||
| 5138 | PHP | 3년 전 | 1507 | ||
| 5137 | MySQL | 3년 전 | 1694 | ||
| 5136 | PHP | 3년 전 | 2000 | ||
| 5135 | PHP | 3년 전 | 1945 | ||
| 5134 | JavaScript |
오토소프트
|
3년 전 | 1098 | |
| 5133 | PHP |
|
3년 전 | 1134 | |
| 5132 | 웹서버 | 3년 전 | 1290 | ||
| 5131 | OS | 3년 전 | 1927 | ||
| 5130 | OS | 3년 전 | 1407 | ||
| 5129 | OS | 3년 전 | 1794 | ||
| 5128 | OS | 3년 전 | 1804 | ||
| 5127 | OS | 3년 전 | 922 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기