Soluzione
Puoi chiamare il metodo toObject per accedere ai campi. Per esempio:
var itemObject = item.toObject(); console.log(itemObject.title); // "foo"Perché
Come fai notare, i campi reali sono memorizzati nel campo _doc del documento.
Ma allora perché console.log(item) => { title: "foo", content: "bar" }?
Dal codice sorgente di Mongoose (document.js), possiamo vedere che il metodo toString di Document chiama il metodo toObject, quindi console.log mostra i campi 'correttamente'. Il codice sorgente è mostrato sotto:
var inspect = require('util').inspect; ... /** * Helper for console.log * * @api public */ Document.prototype.inspect = function(options) { var isPOJO = options && utils.getFunctionName(options.constructor) === 'Object'; var opts; if (isPOJO) { opts = options; } else if (this.schema.options.toObject) { opts = clone(this.schema.options.toObject); } else { opts = {}; } opts.minimize = false; opts.retainKeyOrder = true; return this.toObject(opts); }; /** * Helper for console.log * * @api public * @method toString */ Document.prototype.toString = function() { return inspect(this.inspect()); };