수

node.js MongoDB Find - projection

· 2019-02-04 (월) 22:04:35 · 2925


MongoDB Find - projection

 

find()메서드의 두 번째 매개 변수 projection는 결과에 포함 할 필드를 설명하는 객체입니다.

이 매개 변수는 선택적이며, 생략하면 모든 필드가 결과에 포함됩니다.

예
customers 컬렉션에있는 모든 문서의 "name"및 "address"필드를 반환합니다.

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");
  dbo.collection("customers").find({}, { projection: { _id: 0, name: 1, address: 1 } }).toArray(function(err, result) {
    if (err) throw err;
    console.log(result);
    db.close();
  });
});

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

개발자팁

5,403건

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

+
분류 제목 글쓴이 날짜 조회
PHP 19-06-24 조회 3,192
PHP 19-06-09 조회 3,812
MySQL 19-04-01 조회 4,867
jQuery 19-03-20 조회 4,252
node.js 19-02-12 조회 3,352
node.js 19-02-12 조회 3,087
node.js 19-02-12 조회 3,351
node.js 19-02-07 조회 3,326
node.js 19-02-07 조회 3,064
node.js 19-02-07 조회 3,210
node.js 19-02-04 조회 2,948
node.js 19-02-04 조회 2,926
node.js 19-02-04 조회 3,370
node.js 19-01-31 조회 2,479
node.js 19-01-31 조회 2,629
node.js 19-01-31 조회 3,107
node.js 19-01-28 조회 2,870
node.js 19-01-28 조회 2,952
node.js 19-01-28 조회 2,793
node.js 19-01-22 조회 3,124
node.js 19-01-22 조회 2,886
node.js 19-01-22 조회 3,310
node.js 19-01-16 조회 2,755
node.js
[node.js]
19-01-16 조회 2,650
node.js 19-01-16 조회 9,327
node.js 19-01-12 조회 4,404
node.js 19-01-12 조회 3,006
node.js 19-01-12 조회 3,152
node.js 19-01-11 조회 2,696
node.js 19-01-11 조회 4,052