Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

399
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda