두가지 방식으로


//cors허용

// cors모듈 사용

import cors from 'cors'

app.use(cors())

//express 헤더 추가

app.all('/*', (req, res, next) => {

res.header("Access-Control-Allow-Origin", "*")

res.header("Access-Control-Allow-Headers", "X-Requested-With")

next();


}


현재 아래있는 헤더에 추가하는 방식으로 사용중






'오락기 > node' 카테고리의 다른 글

es6의 모듈  (0) 2018.08.17
새로 개발할 모니터링 리액트용 환경구성  (0) 2018.08.17
webpack  (0) 2018.08.17
ejs 익스프레스 자바스크립트 템플릿  (0) 2018.08.17
express routing static dir  (0) 2018.08.17

 

조회 

 

 

 

등록 

 

 

 

삭제 

 

 

복합인덱스는 항목만 추가해주면된다. 

 

Ex )db.collection.createIndex({ name: 1, site: -1 })  


'오락기 > mongoDB' 카테고리의 다른 글

mongoose.js node 연동  (0) 2018.08.17
query rdb와 동일하게 할려면  (0) 2018.08.17
sort lime skip  (0) 2018.08.17
aggregation pipeline stages  (0) 2018.08.17
distinct + java api  (0) 2018.08.17

import mongoose from 'mongoose' 

let db = mongoose.connection 

db.on('error'console.error); 

db.once('open', () => { 

// CONNECTED TO MONGODB SERVER 

console.log("Connected to mongod server"); 

}); 

mongoose.connect('mongodb://jsplays.iptime.org:27017/resource') 

 

커넥션  이렇게 

mongoose.connect('mongodb://username:password@host:port/database?options...'); 

 

 

let schema = mongoose.Schema 

let testSchema = new schema({ 

title : String, 

auth : String, 

date : { type : Date , default : Date.now} 

}) 

 

 

스키마 지정 

사용되는 스키마는 8종류 

 

  1. String 

  2. Number 

  3. Date 

  4. Buffer 

  5. Boolean 

  6. Mixed 

  7. Objectid 

  8. Array 

 

import mongoose from 'mongoose' 

const schema = mongoose.Schema 

const testSchema = new mongoose.schema ({ 

test : {type : Number , require : true , unique : true}, 

title : String, 

auth : String, 

date : { type : Date , default : Date.now} 

}, 

{ 

timestamps: true 

} 

) 

//콜렉션 이름을 지정하고싶으면 스키마 생성시 옵션으로 넣는다 

// const todoSchema = new mongoose.Schema({..}, { collection: 'my-collection-name' }); 

//모델은 생성자이므로 인스턴스를 생성할수있음으로 속성이나 값을 추가하여 생성할수있다 

const Test = mongoose.model('Test' , testSchema) 

const test = new Test({ 

test : 1, 

title: 'test', 

auth : 'js' 

}) 

또는 

const test = new Test() 

test.test = 1 

test.title = 'test' 

test.auth = 'js' 

const output = mongoose.model('Test' , testSchema) 

export default output 

 

 

관계는 이렇게 될수있다. 

 

 

 


'오락기 > mongoDB' 카테고리의 다른 글

index 관리  (0) 2018.09.28
query rdb와 동일하게 할려면  (0) 2018.08.17
sort lime skip  (0) 2018.08.17
aggregation pipeline stages  (0) 2018.08.17
distinct + java api  (0) 2018.08.17

+ Recent posts