Created
April 13, 2012 17:22
-
-
Save aheckmann/2378491 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
var assert = require('assert') | |
mongoose.connect('localhost', 'testing_findone'); | |
var schema = new Schema({ | |
name: { last: { type: String, required: true} } | |
}); | |
var A = mongoose.model('A', schema); | |
mongoose.connection.on('open', function () { | |
A.findOne({}, ['name'], function (err, doc) { | |
if (err) console.error(err.stack||err); | |
assert.equal(null, doc); | |
console.error('all good'); | |
mongoose.connection.db.dropDatabase(function () { | |
mongoose.connection.close(); | |
}); | |
}); | |
}); |
nice!
This is my next issue, custom validation functions are still called on fields which are not selected.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var assert = require('assert')
mongoose.connect('localhost', 'testing_findone');
var schema = new Schema({
name: {
type: String,
required: true,
validate: [function(str) {
return str.length < 20;
}, 'MaxLength']
},
nick: {
type: String,
required: true
},
soemthing: String
}, {strict: true});
var A = mongoose.model('A', schema);
mongoose.connection.on('open', function () {
var a = new A({
name: 'name',
nick: 'nick'
});
a.save(function(err) {
assert.equal(null, err);
A.findOne({},['nick'], function (err, doc) {
if (err) console.error(err.stack||err);
console.log('"name" in doc should be false but it is - ', 'name' in doc);
doc.nick = 'blubb';
doc.save(function(err) {
console.error(err);
mongoose.connection.db.dropDatabase(function () {
mongoose.connection.close();
});
});
});
});
});
please open a ticket on the repo. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
will test it on my huge model with lots of usecases ...