Getting TypeError: Unknown encoding: 1 while running the server script with Mongoose

Getting TypeError: Unknown encoding: 1 while running the server script with Mongoose

我运行下面的代码用Mongoose将水果名称插入数据库。它确实插入了对象,但随后抛出 TypeError: Unknown encoding: 1 并退出脚本。我尝试更新 Mongoose 和 Mongo 但它没有解决问题。

var mongoose = require('mongoose');
var assert = require('assert');
var Fruits = require('./models/fruits-1');
var url = 'mongodb://localhost:27017/confusion';
mongoose.connect(url);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function(){
    Fruits.create(
        {
            name: 'Apple',
            description: "It's delicious."
        }, function(err, fruit){
            if(err){
                console.log(err);
            }
            else{
                console.log(fruit);
            }
    });
});

我有一个不好的解决方案,删除 console.log(fruit)。

我现在在 Fedora 25 上遇到了同样的问题,代码也是一样的。 而且它今天在 Ubuntu 14.04.

上更快地工作正常

他们都在 v6 中使用 Nvm。

真正的解决方案是将您的 bson 更新到 1.0.3 - 请参阅 this issue(感谢 Blaze Sahlzen)。