I'm using bluebird's promisifyAll with mongoose. When I call saveAsync (the promisified version of save) on a model object, the resolved value of the completed promise is an array with two elements. The first is my saved model object, the second is the integer 1. Not sure what's going on here. Below is example code to reproduce the issue.
var mongoose = require("mongoose");
var Promise = require("bluebird");
Promise.promisifyAll(mongoose);
var PersonSchema = mongoose.Schema({
'name': String
});
var Person = mongoose.model('Person', PersonSchema);
mongoose.connect('mongodb://localhost/testmongoose');
var person = new Person({ name: "Joe Smith "});
person.saveAsync()
.then(function(savedPerson) {
//savedPerson will be an array.
//The first element is the saved instance of person
//The second element is the number 1
console.log(JSON.stringify(savedPerson));
})
.catch(function(err) {
console.log("There was an error");
})
The response I get is
[{"__v":0,"name":"Joe Smith ","_id":"5412338e201a0e1af750cf6f"},1]
I was expecting just the first item in that array, as the mongoose model save() method returns a single object.
Any help would be greatly appreciated!