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);
}
});
});

source
share