Reputation: 49
Using mongoose schema.types.Mixed to read existing collections do not recognized the key/value pairs, the console only show "_id" but when trying to access the other key/values I get an undefined
var UserSchema1 = new mongoose.Schema({ key: {}});
var UserSchema2 = new mongoose.Schema({
userID: Number,
userName: String,
password: String});
var User = mongoose.model('user', UserSchema1,'info' );
router.get('/', function(req, res) {
User.find({}, function(err, docs) {
var s = docs;
console.log(s[0].userName);
console.log(s[0]._id);
res.render('userinfo', {users : docs});
});
});
---- OUTPUT ----
**UserSchema1** - **UserSchema2**
console.log(s[0].userName); undefined mongo
console.log(s[0]._id); 241245j23j6l26l6 afa88asf8989asfa
--jade.js--
ul
each user in users
li #{user._id}
li #{user['userName']}
Shows only li with the _id
but it creates empty li supposedly for user.name
Upvotes: 1
Views: 4004
Reputation: 696
In order to work, you have to use Schema.Types.Mixed
(uppercased each word) as you can see here (search for Schema.Types.Mixed
) and without curly braces {}
.
Upvotes: 1
Reputation: 393
To use this data type, you can not place {}
, but schema.types.Mixed
. So mongoose is an object which is to be saved.
Upvotes: 1