I'm populating my DB with some dummy data where I'm trying to add a user. A user object is created but none of the properties are save... whats up?
app.get('/setup', function (req, res) {
User.findOne({ name: "Nick" }, function (err, user) {
if (user == undefined) {
var nick = new User({
name: "Nick",
}).save();
res.json({ "success": true, "msg": "user created" });
} else {
res.json({ "success": true, "msg": "user existed" });
}
});
});
calling this returns "user created". Here is my method to output all users:
app.get('/users', function(req, res) {
User.find({}, function(err, user) {
res.json(user);
});
});
The output here is
[
{
"_id": "565772db5f6f2d1c25e999be",
"__v": 0
},
{
"_id": "5657734ba859fefc1dca77db",
"__v": 0
},
{
"_id": "5657738ba859fefc1dca77dc",
"__v": 0
},
{
"_id": "565774f1cf99a2b81fca1e7f",
"__v": 0
},
{
"_id": "565775f0cf99a2b81fca1e80",
"__v": 0
}
]
Where I've tried to add "Nick" a couple of times noe... any input? :D
My Mongoose model, located in its own Model.js file with other models:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// set up a mongoose model and pass it using module.exports
module.exports = mongoose.model('User', new Schema({
name: String,
password: String,
}));