I've been trying to create a database/model with Mongoose which is basically just a user database where the username is unique. Sounds simple enough, but for some reason I've been unable to do so.
What I've got so far is this:
var mongoose = require('mongoose').Mongoose,
db = mongoose.connect('mongodb://localhost/db');
mongoose.model('User', {
properties: [
'name',
'age'
],
cast: {
name: String,
age: Number
},
//indexes: [[{name:1}, {unique:true}]],
indexes: [
'name'
]
/*,
setters: {},
getters: {},
methods: {}
*/
});
var User = db.model('User');
var u = new User();
u.name = 'Foo';
u.save(function() {
User.find().all(function(arr) {
console.log(arr);
console.log('length='+arr.length);
});
});
/*User.remove({}, function() {});*/
It just doesn't work. The database is created alright, but the username is not unique. Any help or knowledge of what I'm doing wrong?
-freeall