Node.js MongoDB 정렬
Node.js MongoDB 정렬
결과 정렬
이 sort()방법을 사용하면 결과를 오름차순 또는 내림차순으로 정렬 할 수 있습니다.
이 sort()메서드는 하나의 매개 변수 인 정렬 순서를 정의하는 객체를 사용합니다.
예
결과를 이름순으로 알파벳 순으로 정렬하십시오.
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 mysort = { name: 1 };
dbo.collection("customers").find().sort(mysort).toArray(function(err, result) {
if (err) throw err;
console.log(result);
db.close();
});
});
=================================
var mysort = {name: 1};
name에 숫자가 1또는 -1일 경우
{name : 1} // 오름차순
{name : -1} // 내림차순
게시판 목록
개발자팁
개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4826 | jQuery | 8년 전 | 1672 | ||
| 4825 | JavaScript | 8년 전 | 2739 | ||
| 4824 | jQuery | 8년 전 | 1464 | ||
| 4823 | jQuery | 8년 전 | 1726 | ||
| 4822 | jQuery | 8년 전 | 1810 | ||
| 4821 | jQuery | 8년 전 | 1638 | ||
| 4820 | jQuery | 8년 전 | 1647 | ||
| 4819 | jQuery | 8년 전 | 1325 | ||
| 4818 | jQuery | 8년 전 | 1969 | ||
| 4817 | jQuery | 8년 전 | 2407 | ||
| 4816 | jQuery | 8년 전 | 1704 | ||
| 4815 | jQuery | 8년 전 | 1420 | ||
| 4814 | jQuery | 8년 전 | 1839 | ||
| 4813 | jQuery | 8년 전 | 5412 | ||
| 4812 | 기타 | 8년 전 | 3163 | ||
| 4811 | jQuery | 8년 전 | 1543 | ||
| 4810 | jQuery | 8년 전 | 1714 | ||
| 4809 | jQuery | 8년 전 | 1803 | ||
| 4808 | PHP |
|
8년 전 | 5084 | |
| 4807 | node.js |
|
8년 전 | 4118 | |
| 4806 | jQuery | 8년 전 | 2217 | ||
| 4805 | jQuery | 8년 전 | 1652 | ||
| 4804 | jQuery | 8년 전 | 1201 | ||
| 4803 | jQuery | 8년 전 | 1911 | ||
| 4802 | jQuery | 8년 전 | 1417 | ||
| 4801 | jQuery | 8년 전 | 1522 | ||
| 4800 | jQuery | 8년 전 | 1742 | ||
| 4799 | jQuery | 8년 전 | 1985 | ||
| 4798 | jQuery | 8년 전 | 1521 | ||
| 4797 | jQuery | 8년 전 | 1456 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기