Mongoose returns Mongo object, but can't access property on it Mongoose returns Mongo object, but can't access property on it mongoose mongoose

Mongoose returns Mongo object, but can't access property on it


i recommend you use autoincrement mongoose plugin, somthing like this

var mongoose = require('mongoose');var autoIncrement = require('mongoose-auto-increment');var connection = mongoose.createConnection("mongodb://localhost/db");autoIncrement.initialize(connection);var GameSchema = {    "gameId":       {type: Number},    "gameNickname": {type: String}}GameSchema.plugin(autoIncrement.plugin, { model: 'Game', field: 'gameId' });mongoose.model('Game', GameSchema);

after this you can save your game with autoinc, for example:

var Game = mongoose.model('Game');

function createNewGame(nickname){    return new Game({gameNickname: nickname}).save(function(err, res){      console.log(res);      //some code...   })}

after execute this code you should have somnthing like this:

{    _id:          "555d83d5bb0d4e3c352d896f",    gameNickname: "nickname",    gameId:        1}