KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Update : Been some time. But back then decided not to use Mongoose. Main reason being that we couldn't really come up with a great reason for using an ORM when using mongo and javascript. 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?
Tags (comma-separated)
Save Edits
Cancel