0

I´m currently developing a node.js application with mongodb/mongoose.js

My code for creating the schema is (mongo.js):

'use strict';
var mongoose = require('mongoose');
var schema = mongoose.Schema({
    conID: Number
});
module.exports = mongoose.model('stack overflow', schema);

My server.js code is:

var mongo = require('/var/www/models/mongo');
mongoose.connect('mongodb://localhost/stackoverflow');
var test = new mongo({
  conID: 1
});
test.save(function(err,test) {
  if (err) console.log(err);

  console.log('test saved');
    console.log(test);
});
mongo.find({ conID: 1 }, function(err, users) {
  if (err) console.log('fehler');
  console.log(users.conID);
});

But when I look into the log my "test" or my "user.conID" is like:

error:  strictMode=true, selected=undefined, shardval=undefined, saveError=undefined, validationError=undefined, adhocPaths=undefined, removing=undefined, inserting=true, version=undefined, , _id=undefined, populate=undefined, populated=undefined, wasPopulated=false, scope=undefined, , , , , , , stateNames=[require, modify, init, default, ignore], map=function () {
    var numArgs = arguments.length,
        states = utils.args(arguments, 0, numArgs - 1),
        callback = arguments[numArgs - 1];

    if (!states.length) states = this.stateNames;

    var _this = this;

    var paths = states.reduce(function(paths, state) {
      return paths.concat(Object.keys(_this.states[state]));
    }, []);
.
.
.

and a few hundred lines more of code like that.

Can anyone help? Thanks!

5
  • if (err) console.log(err); is error code. Add return - if (err) return console.log(err); Commented Aug 11, 2016 at 15:09
  • hum do you have a mongo.connect somewhere ? Commented Aug 11, 2016 at 15:09
  • yeah, i forgot to copy&paste my mongo.connect, sry ;) Commented Aug 11, 2016 at 15:10
  • What is this ? var mongo = require('/var/www/models/mongo'); Commented Aug 11, 2016 at 15:12
  • it is how i load my schema into my server.js Commented Aug 11, 2016 at 15:16

1 Answer 1

0

users is array so You cant do this.

console.log(users.conID);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! users[0].conID works for my find() function. but i also get the above error for my save function. any idea? and how can i output the complete array?
From mongoosejs.com/docs/models.html save method doesn't have 2 parameter in return function. So i think this is the problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.