爲什麼我試圖在終端中運行node file.js時會收到此錯誤消息?我嘗試在「mongoose.connect ...」之前加入「mongoose.Promise = global.Promise」,但它仍然無效。「Mongoose mpromise已被棄用」錯誤
DeprecationWarning:貓鼬:mpromise(貓鼬的默認承諾庫)已被棄用,插上自己的諾言庫,而不是:http://mongoosejs.com/docs/promises.html
這裏的源代碼:
var Product = require('../models/product');
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect('localhost:27017/shopping');
var products = [
new Product({
imagePath: 'https://upload.wikimedia.org/wikipedia/en/5/5e/Gothiccover.png',
title: 'Gothic 5 Video Game',
description: 'Awesome Game!!!!',
price: 10
}),
new Product({
imagePath: 'https://upload.wikimedia.org/wikipedia/en/5/5e/Gothiccover.png',
title: 'Gothic 4 Video Game',
description: 'Also Awesome Game!!!!',
price: 20
}),
new Product({
imagePath: 'https://upload.wikimedia.org/wikipedia/en/5/5e/Gothiccover.png',
title: 'Gothic 3 Video Game',
description: 'best game ever!!!!',
price: 15
}),
new Product({
imagePath: 'https://upload.wikimedia.org/wikipedia/en/5/5e/Gothiccover.png',
title: 'Gothic 2 Video Game',
description: 'top notch!!!',
price: 50
})
];
var done = 0;
for (var i = 0; i < products.length; i++) {
products[i].save(function(err, result){
done++;
if (done === products.length) {
exit();
}
});
}
function exit() {
mongoose.disconnect();
}
這不是一個錯誤,它是一個警告。 –
似乎是一個重複:http://stackoverflow.com/questions/38138445/node3341-deprecationwarning-mongoose-感謝 –