ScaV
ScaV

Reputation: 175

mongoose find().all()

Windows 7 x64, node.js, mongoose from npm.

var sys = require('util');
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:28960/test_mongoose');
var Schema = mongoose.Schema;

//Model

var UserSchema = new Schema({

    username    : String,
    uid         : String,
    messaged_on : Date
});

mongoose.model('User', UserSchema);
var User = mongoose.model('User');

// create a new user

var user = new User({

    uid         : '54321',
    username    : 'Bob',
    messaged_on : Date.now()
});

user.save( function (err) {

    if (err)
        return;
    console.log('Saved');

    User.find().all(function(user) {
        console.log('beep');
    });
});

Connection to mongod accepted, database 'test_mongoose' created.

Console print 'Saved', but 'beep' not. I am newbie in mongoose, but, what is a prolem? Why do User.find().add() not call function back (user)? Sorry for my bad english.

Maybe is it normal?

Upvotes: 0

Views: 10860

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 312035

You should be calling User.find(... instead of User.find().all(.... The all method invokes the $all operator which is only used when matching arrays.

Upvotes: 5

Related Questions