여러 문서 삽입
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();
});
});
게시글 목록
| 번호 | 제목 |
|---|---|
| 16801 | |
| 16798 | |
| 16796 | |
| 16795 | |
| 16791 | |
| 16790 | |
| 16785 | |
| 16777 | |
| 16776 | |
| 16766 | |
| 16760 | |
| 16759 |
JavaScript
전화번호 및 휴대번호 자동하이픈(-)
2
|
| 16740 | |
| 16737 | |
| 16735 | |
| 16728 | |
| 16713 |
PHP
PHP Router
17
|
| 16700 | |
| 16691 | |
| 16669 | |
| 16668 |
MySQL
특정 row의 index 값 구하기
5
|
| 16660 | |
| 16655 | |
| 16654 | |
| 16647 | |
| 16639 | |
| 16637 | |
| 16634 | |
| 16629 | |
| 16620 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기