Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

398
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!