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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5186 | PHP |
swallow
|
2년 전 | 942 | |
| 5185 | PHP |
swallow
|
2년 전 | 962 | |
| 5184 | PHP |
swallow
|
2년 전 | 537 | |
| 5183 | PHP |
swallow
|
2년 전 | 845 | |
| 5182 | PHP |
swallow
|
2년 전 | 778 | |
| 5181 | 기타 |
swallow
|
2년 전 | 1021 | |
| 5180 | 2년 전 | 574 | |||
| 5179 | 기타 |
swallow
|
2년 전 | 1434 | |
| 5178 | PHP |
swallow
|
2년 전 | 796 | |
| 5177 | JavaScript |
swallow
|
2년 전 | 1490 | |
| 5176 | PHP |
swallow
|
2년 전 | 1189 | |
| 5175 | 2년 전 | 566 | |||
| 5174 | 기타 | 2년 전 | 816 | ||
| 5173 | PHP |
|
2년 전 | 969 | |
| 5172 | PHP |
|
2년 전 | 1253 | |
| 5171 | 기타 |
그누GPT
|
2년 전 | 1556 | |
| 5170 | PHP |
|
2년 전 | 1051 | |
| 5169 | PHP |
|
2년 전 | 1226 | |
| 5168 | PHP |
|
2년 전 | 1200 | |
| 5167 | JavaScript |
|
2년 전 | 997 | |
| 5166 | MySQL | 2년 전 | 1191 | ||
| 5165 | MySQL | 2년 전 | 1256 | ||
| 5164 | PHP | 2년 전 | 1501 | ||
| 5163 | OS |
|
2년 전 | 843 | |
| 5162 | 웹서버 |
|
2년 전 | 892 | |
| 5161 | 웹서버 |
|
2년 전 | 975 | |
| 5160 | PHP |
|
2년 전 | 843 | |
| 5159 | PHP |
|
2년 전 | 907 | |
| 5158 | PHP |
|
2년 전 | 917 | |
| 5157 | PHP |
|
2년 전 | 943 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기