Lỗi mongoDB khi đưa lên server?
-
Phiên bản mongodb sử dụng ở local
Phiên bản mongo sử dụng ở server
Đoạn code này mình chạy ở local không hề bị lỗi gì cảexports.clickDocThongBao = function (req, res) { return new Promise((resolve, reject) => { // console.log('Doc Thong Bao ====>', req.session.passport.user) usersModel.findByIdAndUpdate(req.session.passport.user, { $set: { 'thongBao.$[i].trangThaiThongBao': 2 } }, { "arrayFilters": [{ "i._id": mongoose.Types.ObjectId(req.body.idThongBao) }] }, (err, doc) => { console.log(doc) res.json({ status:true }) }).exec(); }) }
Nhưng khi chạy ở server thì gặp lỗi
││ server > (node:1844) UnhandledPromiseRejectionWarning: MongoError: The featureCompatibilityVersion must be 3.6 to use arrayFilters. See │ │ ││ http://dochub.mongodb.org/core/3.6-feature-compatibility. │ │ ││ server > at /var/www/html/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:598:61 │ │ ││ server > at authenticateStragglers (/var/www/html/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:516:16) │ │ ││ server > at Connection.messageHandler (/var/www/html/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:552:5) │ │ ││ server > at emitMessageHandler (/var/www/html/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:309:10) │ │ ││ server > at Socket.<anonymous> (/var/www/html/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:452:17) │ │ ││ server > at Socket.emit (events.js:182:13) │ │ ││ server > at Socket.EventEmitter.emit (domain.js:442:20) │ │ ││ server > at addChunk (_stream_readable.js:283:12) │ │ ││ server > at readableAddChunk (_stream_readable.js:264:11) │ │ ││ server > at Socket.Readable.push (_stream_readable.js:219:10) │ │ ││ server > at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) │ │ ││ server > (node:1844) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an │ │ ││ async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
Chức năng mình đang làm là khi người dùng bấm vào xem thông báo sẽ chuyển đổi trạng thái thông báo thành 1 hay đã đọc
https://bomhai.fun/uploads/localhost.mp4 clip o local
đây là clip ở server
https://bomhai.fun/uploads/host.m4v
-
Thông báo lỗi thể hiện rõ rồi kìa
Bạn vào link dochub mongo đọc rồi tìm cách sửa thôi
-
@CodeConCat mình đã xem qua và thấy cách mình giống trong doc của nó mà.
-
@CodeConCat
Trong docdb.runCommand({ update: "students2", updates: [ { q: { }, u: { $set: { "grades.$[elem].mean" : 100 } }, arrayFilters: [ { "elem.grade": { $gte: 85 } } ], multi: true } ] })
code của mình
usersModel.findByIdAndUpdate(req.session.passport.user, { $set: { 'thongBao.$[i].trangThaiThongBao': 2 } }, { "arrayFilters": [{ "i._id": idNguoiDangNhap }] }
-
được rồi. chạy thêm dòng
db.adminCommand({setFeatureCompatibilityVersion: "3.6"})
trên server là chạy bình thường