Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ { _id: 57682f69feaf405c51fdf144,
- email: 'testuser1@testdomain.com',
- username: 'testuser' },
- { username: 'sevilayha', _id: 5768d36c4c243de7422f681e, __v: 0 } ]
- // With Mongoose, everything is derived from a Schema. Let's get a reference to it and define our users.
- var userSchema = mongoose.Schema({
- name: String,
- username: { type: String, required: true, unique: true },
- password: { type: String, required: true },
- admin: Boolean,
- location: String,
- meta: {
- age: Number,
- website: String
- },
- created_at: Date,
- updated_at: Date
- });
- // The next step is compiling our schema into a Model.
- var User = mongoose.model('User', userSchema);
- app.get("/", function(req, res) {
- var updateQuery = {
- date: Date.now()
- };
- User.findOne({ username: /^sevilayha/ }, function (err, user) {
- if (err) return console.error(err);
- user.update({
- $push: updateQuery,
- $set: { size: 'large' },
- email: 'test@example.com'
- });
- res.status(200).json(user);
- });
- User.find(function (err, users) {
- if (err) return console.error(err);
- console.log(users);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement