Node.js MongoDB Insert

· 6년 전 · 2286

Node.js MongoDB Insert

 

컬렉션에 삽입

 

insertOne()메서드 의 첫 번째 매개 변수는 삽입 할 문서의 각 필드 이름과 값을 포함하는 객체입니다.

또한 오류 또는 삽입 결과로 작업 할 수있는 콜백 함수를 사용합니다.



"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: "Company Inc", address: "Highway 37" };
  dbo.collection("customers").insertOne(myobj, function(err, res) {
    if (err) throw err;
    console.log("1 document inserted");
    db.close();
  });
});

위의 코드를 "demo_mongodb_insert.js"라는 파일에 저장하고 파일을 실행하십시오.

"demo_mongodb_insert.js"를 실행하십시오.

C:\Users\Your Name>node demo_mongodb_insert.js

|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

개발자팁

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
MySQL 6년 전 조회 4,195
jQuery 6년 전 조회 3,675
node.js 6년 전 조회 2,727
node.js 6년 전 조회 2,466
node.js 6년 전 조회 2,695
node.js 6년 전 조회 2,679
node.js 6년 전 조회 2,435
node.js 6년 전 조회 2,581
node.js 6년 전 조회 2,326
node.js 6년 전 조회 2,310
node.js 6년 전 조회 2,778
node.js 6년 전 조회 1,908
node.js 6년 전 조회 2,038
node.js 6년 전 조회 2,499
node.js 6년 전 조회 2,287
node.js 6년 전 조회 2,364
node.js 6년 전 조회 2,174
node.js 6년 전 조회 2,491
node.js 6년 전 조회 2,287
node.js 6년 전 조회 2,725
node.js 7년 전 조회 2,134
node.js
[node.js]
7년 전 조회 2,059
node.js 7년 전 조회 8,731
node.js 7년 전 조회 3,799
node.js 7년 전 조회 2,437
node.js 7년 전 조회 2,541
node.js 7년 전 조회 2,125
node.js 7년 전 조회 3,425
node.js 7년 전 조회 2,262
node.js 7년 전 조회 2,028
🐛 버그신고