mongoose(18)
-
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 -
Azure CosmosDB 4.0 _id 값 new Object가 같이 나오는 현상
Azure CosmosDB 3.6를 mongoose를 연결하여 쓰는중에 다른 프로젝트를 구성해야 하는 기회가 생겨 4.0으로 진행하는 중에 3.6에서는 _id를 콘솔로 찍으면 안에 인덱스 값만 61398a83e93dda374c41b693 이렇게만 찍혔는데 4.0에서는 콘솔 값 이 new ObjectId("61398a83e93dda374c41b693") 이렇게 찍혀서 String으로 값을 전부 가져오는 줄 알고 헛짓을 했다. new ObjectId("61398a83e93dda374c41b693")으로 나와도 놀라지말고 그대로 사용해주면 된다!
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 -
Mongoose 디비연결, Model 생성
디비연결 npm i mongoose 설치 후 Mongoose를 이용하여 db.js에서 DB와 연결 // ./db/db.js var mongoose = require('mongoose') module.exports = () => { function connect () { var db = mongoose.connection db.on('error', function () { console.log('Connected to mongod failed!') }) db.once('open', function () { console.log('Connected to mongod server') }) mongoose.connect('mongodb://DB유저 이름:' + DB비밀번호 + '@DB주소:호스트번호/해당 DB이..
2020.05.26