MongoDB, Mongoose(16)
-
Mongoose 다중 connect 연결 방법
한개 connection 연결방법 : https://crispypotato.tistory.com/25 connection 링크를 여러개 연결해야 하는 경우 connection을 다중으로 만들어서 연결을 만들면 에러가 발생한다. 해결 방법 * 주요 * mongoose.[본인이 사용 할 connect이름] = mongoose.createConnection()으로 설정한다. const mongoose = require('mongoose') module.exports = { connect: () => { mongoose.product = mongoose.createConnection(process.env.DB, { useNewUrlParser: true, useUnifiedTopology: true }, (er..
2022.02.11 -
mongoose options usecreateindex,usefindandmodify are not supported 에러 해결 방법
mongoose를 다른 프로젝트를 진행하려고 전에 설정 한 것과 똑같이 다시 설정을 하고 실행을 하는데 이런 오류가 발생했다. 원인은 mongoose가 6.0 버전 이상이 되어 디폴트로 지원해주는 값이 있어 오류가 발생했다. useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false 의 설정값을 지워 주고 실행 해주면 된다. 디비연결 할때 const mongoose = require('mongoose') module.exports = () => { function connect () { mongoose.connect(process.env.DB, { }, (err) => { if (err) { c..
2021.11.04 -
Mongoose 필드(field)명 변경, Object 키 값 변경
const January = new Schema({ rankPoint: { type:Number }, lastWeekPoint: { type:Number }, totalScore: { type:Number }, rank: { type:Number }, }); "January":{ "rankPoint" : 0, "lastWeekPoint" : 0, "totalScore" : 0, "rank" : 3 } January 스키마가 구성되어 있다. lastWeekPoint를 lastDayPoint로 바꾸려고 할때 $rename을 사용한다. 사용방법 January.findOneAndUpdate({},{$rename: {lastWeekPoint: 'lastDayPoint' }}, {multi: true}) 명령어를 ..
2021.04.22 -
Mongoose 페이징 처리 (Node)
몽구스를 이용하여 페이징 처리 방법 post라는 모델에 있는 게시물을 페이징 처리 모델 //모델 const Post = require('../models/post') 프론트 요청값 // 프론트에서 요청하는 페이지번호, 요청하는 최대 게시물 숫자 //해당 페이지 번호 const page = req.params.page //최대 요청 수 const maxPost = req.params.maxPost 페이징 함수 const paging = (page, totalPost, maxPost) => { // 페이지에 나오는 최대 게시물 수 const maxPost = maxPost // 페이지에 나오는 최대 페이지 수 const maxPage = maxPost // 받아오는 page가 스트링일경우 Number형으로 ..
2021.02.24 -
Cosmos DB에 mongoose sort기능 사용시 오류 The index path corresponding to the specified order-by item is excluded
로컬 mongoDB는 mongoose의 sort 기능이 정상적으로 작동한다. 하지만 cosmosDB에서는 pk키, unique키에만 sort 기능이 작동한다. docs.microsoft.com/en-us/azure/cosmos-db/mongodb-troubleshoot Troubleshoot common errors in Azure Cosmos DB's API for Mongo DB This doc discusses the ways to troubleshoot common issues encountered in Azure Cosmos DB's API for MongoDB. docs.microsoft.com pk키나 unique키가 아닌 컬럼를 사용하면 이런 오류가 발생한다. 주의하자. The index ..
2020.10.08 -
Moogoose "__v" 필드
moogoose를 사용하면서 결과값을 보면 맨 밑에 쯤에 "__v"가 있다. 버전 키라고 하는데 문서의 내부 개정판을 설명하고 기본값은 0이다. mongoDB에서 바로 값을 넣으면 생기지 않지만 moogoose 통해 데이터가 삽입이 되면 생긴다. __v를 없애고 싶으면 스키마를 만드는 부분에 { versionKey : false } 를 추가해주면된다 var UserSchema = new mongoose.Schema({ userName: String, }, { versionKey: false }); https://riucc.tistory.com/m/526?category=764382 [MongoDB] - Mongoose __v 제거하기 ○ MongoDB Mongoose __v 제거하기 mongoose를 통..
2020.06.10