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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5336 | 1년 전 | 952 | |||
| 5335 | 1년 전 | 974 | |||
| 5334 | 1년 전 | 884 | |||
| 5333 | 1년 전 | 714 | |||
| 5332 |
바다클라우드
|
1년 전 | 3643 | ||
| 5331 |
뽕엄능브라
|
1년 전 | 1670 | ||
| 5330 | 1년 전 | 1328 | |||
| 5329 |
|
1년 전 | 2650 | ||
| 5328 | 1년 전 | 2453 | |||
| 5327 | 1년 전 | 3644 | |||
| 5326 | 1년 전 | 1547 | |||
| 5325 | JavaScript |
|
1년 전 | 687 | |
| 5324 | OS | 1년 전 | 752 | ||
| 5323 | PHP |
|
1년 전 | 892 | |
| 5322 | PHP |
|
1년 전 | 788 | |
| 5321 | PHP |
|
1년 전 | 648 | |
| 5320 | PHP |
|
1년 전 | 753 | |
| 5319 | PHP |
techstar
|
1년 전 | 799 | |
| 5318 | JavaScript |
|
1년 전 | 665 | |
| 5317 | PHP |
|
1년 전 | 611 | |
| 5316 | PHP |
|
1년 전 | 574 | |
| 5315 | PHP |
|
1년 전 | 685 | |
| 5314 | PHP |
|
1년 전 | 665 | |
| 5313 | PHP |
techstar
|
1년 전 | 764 | |
| 5312 | 정규표현식 |
|
1년 전 | 642 | |
| 5311 | JavaScript |
|
1년 전 | 702 | |
| 5310 | PHP |
|
1년 전 | 2116 | |
| 5309 | PHP |
techstar
|
1년 전 | 1605 | |
| 5308 | PHP |
techstar
|
1년 전 | 673 | |
| 5307 | node.js |
swallow
|
1년 전 | 1427 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기