컴퓨터
mongojs 모듈
sayyesdoit
2019. 3. 30. 19:35
기능
Node.js 에서 mongodb 를 사용할 수 있게 해 준다.
설치
npm install --save mongojs
데이터 조회
const mongojs = require("mongojs");
const db = mongojs("데이터베이스이름");
const mycollection = db.collection("컬렉션 이름");
mycollection.find(function (error, data) {
console.log(data);
});
데이터 삽입
const mongojs = require("mongojs");
const db = mongojs("데이터베이스이름");
const mycollection = db.collection("컬렉션 이름");
mycollection.save({id: "lee", phone: "010-1234-9506"}, function (err) {
console.log(err);
});
ObjectId 검색
const ObjectId = mongojs.ObjectId;
db.users.find({"_id": ObjectId(id)}, function(err, user){...}