Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

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

I am running the following code to insert fruit names into the database with Mongoose. It does insert the object but then it throws a TypeError: Unknown encoding: 1 and exits the script. I tried updating Mongoose and Mongo but it 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's delicious."
        }, function(err, fruit){
            if(err){
                console.log(err);
            }
            else{
                console.log(fruit);
            }
    });
});

enter image description here

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

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

I had the same problem now on Fedora 25, with the same kind of code. And it worked normally sooner today on Ubuntu 14.04.

Both of them are using Nvm with v6.

over 4 years ago · Santiago Trujillo Denunciar

0

The real solution is to update your bson to 1.0.3 - see this issue (thanks Blaze Sahlzen).

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda