Getting TypeError: Unknown Encoding: 1 when starting script server using Mongoose

I am running the following code to insert fruit names into a database using Mongoose. It inserts an object, but then it throws TypeError: Unknown encoding: 1 and exits the script. I tried updating Mongoose and Mongo, but this did not solve the problem.

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 delicious."
        }, function(err, fruit){
            if(err){
                console.log(err);
            }
            else{
                console.log(fruit);
            }
    });
});

enter image description here

+4
source share
2 answers

I have a bad working solution, remove console.log (fruits).

I had the same problem now on Fedora 25 with the same code. And it worked fine earlier today on Ubuntu 14.04.

Both of them use Nvm with v6.

+3

- bson 1.0.3 - . ( Blaze Sahlzen).

+2

Source: https://habr.com/ru/post/1665682/


All Articles