Mongo에 Mongoose 연결하기 오류

개발자가 되고 싶어요·2023년 1월 30일
0

ERROR

목록 보기
1/2
post-thumbnail

mongoose를 연결하면서 두 개의 오류를 얻었다. 😱 이건 또 어떻게 해결하나 싶었지만 해결이 매우 쉬운 오류였다

// err 1
(node:3577) [MONGOOSE] DeprecationWarning: Mongoose: the `strictQuery` option will be switched back to `false` by default in Mongoose 7. Use `mongoose.set('strictQuery', false);` if you want to prepare for this change. Or use `mongoose.set('strictQuery', true);` to suppress this warning.
(Use `node --trace-deprecation ...` to show where the warning was created)
/Users/eeeee/Desktop/mongoose/node_modules/mongoose/lib/connection.js:825
  const serverSelectionError = new ServerSelectionError();
                               ^
// err 2
MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
    at Connection.openUri (/Users/eeeee/Desktop/mongoose/node_modules/mongoose/lib/connection.js:825:32)
    at /Users/eeeee/Desktop/mongoose/node_modules/mongoose/lib/index.js:409:10
    at /Users/eeeee/Desktop/mongoose/node_modules/mongoose/lib/helpers/promiseOrCallback.js:41:5
    at new Promise (<anonymous>)
    at promiseOrCallback (/Users/eeeee/Desktop/mongoose/node_modules/mongoose/lib/helpers/promiseOrCallback.js:40:10)
    at Mongoose._promiseOrCallback (/Users/eeeee/Desktop/mongoose/node_modules/mongoose/lib/index.js:1262:10)
    at Mongoose.connect (/Users/eeeee/Desktop/mongoose/node_modules/mongoose/lib/index.js:408:20)
    at Object.<anonymous> (/Users/eeeee/Desktop/mongoose/index.js:3:10)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) {
      'localhost:27017' => ServerDescription {
        address: 'localhost:27017',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 21603685,
        lastWriteDate: 0,
        error: MongoNetworkError: connect ECONNREFUSED ::1:27017
            at connectionFailureError (/Users/eeeee/Desktop/mongoose/node_modules/mongodb/lib/cmap/connect.js:387:20)
            at Socket.<anonymous> (/Users/eeeee/Desktop/mongoose/node_modules/mongodb/lib/cmap/connect.js:310:22)
            at Object.onceWrapper (node:events:628:26)
            at Socket.emit (node:events:513:28)
            at emitErrorNT (node:internal/streams/destroy:151:8)
            at emitErrorCloseNT (node:internal/streams/destroy:116:3)
            at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
          cause: Error: connect ECONNREFUSED ::1:27017
              at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1487:16) {
            errno: -61,
            code: 'ECONNREFUSED',
            syscall: 'connect',
            address: '::1',
            port: 27017
          },
          [Symbol(errorLabels)]: Set(1) { 'ResetPool' }
        },
        topologyVersion: null,
        setName: null,
        setVersion: null,
        electionId: null,
        logicalSessionTimeoutMinutes: null,
        primary: null,
        me: null,
        '$clusterTime': null
      }
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined
}

구글링으로 얻어낸 답변은 어이없게도

This error is probably occur because the mongo dB services is not started yet what you have to do is Go to control panel Double click on services then search for mongodb.exe and then click on start its for window user I hope it would be work.

https://www.mongodb.com/community/forums/t/i-am-getting-this-error-const-serverselectionerror-new-serverselectionerror/162573
킥킥 ( mongodb community 형님 압도적 감사 🫡 )

미띤 @_@ 하고 확인해보니 진짜 mongdb가 꺼져있어서 나는 오류였다.
이후 mongdb 실행해주니 해결완료 ~~ ^^

뜬금 moongodb 실행, 종료 코드 필요할 수도 있으니까

// 실행 brew services start mongodb-community
// 종료 brew services stop mongodb-community

그렇다면 두 번째 오류는 해결 그러나 첫 번째 오류는 미해결 상태

mongoose.set('strictQuery',false);
(node:3577) [MONGOOSE] DeprecationWarning: Mongoose: the strictQuery option will be switched back to false by default in Mongoose 7. Use mongoose.set('strictQuery', false); if you want to prepare for this change. Or use mongoose.set('strictQuery', true); to suppress this warning.

터미널 오류코드에서 입력하라는 코드를 모두 입력해봤지만 결과는 같았다.

mongoose.set('strictQuery', false); 

mongoose.set('strictQuery', true);

더 찾아보면서 해결해보니 첫 번째 보다 더 심한 어이없는 오류였다랄까?

나는 js파일에서

mongoose.connect("mongodb://localhost:27017/test");

이걸 먼저 입력하고

mongoose.set('strictQuery',false);

요걸 뒤에 써서 났던 오류였다. 🌝

// 오류코드
const mongoose = require('mongoose');

mongoose.connect("mongodb://localhost:27017/test");
mongoose.set('strictQuery',false);

https://stackoverflow.com/questions/74747476/deprecationwarning-mongoose-the-strictquery-option-will-be-switched-back-to

그러니 오류를 해결할 코드는 바로

const mongoose = require('mongoose');

mongoose.set('strictQuery',false);
mongoose.connect("mongodb://localhost:27017/test");

요거다.. 문제해결 완료...

profile
I want to be a Backend Developer

0개의 댓글