|
@@ -0,0 +1,117 @@
|
|
|
+// const _ = require("lodash");
|
|
|
+// const users = [{
|
|
|
+// email: "a@a.com",
|
|
|
+// username: "Alex",
|
|
|
+// password: "pass"
|
|
|
+// }];
|
|
|
+
|
|
|
+// module.exports = {
|
|
|
+// create(email, username, password){
|
|
|
+// let user = {
|
|
|
+// email,
|
|
|
+// username,
|
|
|
+// password
|
|
|
+// };
|
|
|
+
|
|
|
+// users.push(user);
|
|
|
+
|
|
|
+// return user;
|
|
|
+// },
|
|
|
+// find(email){
|
|
|
+// return _.find(users, (user) => {
|
|
|
+// return user.email === email;
|
|
|
+// });
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// const mongoose = require('mongoose');
|
|
|
+// const Schema = mongoose.Schema;
|
|
|
+
|
|
|
+// const userSchema = new Schema
|
|
|
+
|
|
|
+
|
|
|
+// const mongoose = require('mongoose');
|
|
|
+// mongoose.connect('mongodb://localhost:27017/blog');
|
|
|
+
|
|
|
+// const Cat = mongoose.model('Cat', { name: String });
|
|
|
+
|
|
|
+// const kitty = new Cat({ name: 'Zildjian' });
|
|
|
+// kitty.save().then(() => console.log('meow'));
|
|
|
+
|
|
|
+
|
|
|
+// const mongoose = require('mongoose');
|
|
|
+// const Schema = mongoose.Schema;
|
|
|
+
|
|
|
+// const blogSchema = new Schema({
|
|
|
+// title: String,
|
|
|
+// author: String,
|
|
|
+// body: String,
|
|
|
+// comments: [{ body: String, date: Date }],
|
|
|
+// date: { type: Date, default: Date.now },
|
|
|
+// hidden: Boolean,
|
|
|
+// meta: {
|
|
|
+// votes: Number,
|
|
|
+// favs: Number
|
|
|
+// }
|
|
|
+// });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// const mongoose = require('mongoose');
|
|
|
+// const Schema = mongoose.Schema;
|
|
|
+// const User2 = new mongoose.Schema({
|
|
|
+// username : {
|
|
|
+// type: String,
|
|
|
+// unique: true,
|
|
|
+// required: true
|
|
|
+// },
|
|
|
+// password : {
|
|
|
+// type: String,
|
|
|
+// required: true
|
|
|
+// }
|
|
|
+// })
|
|
|
+
|
|
|
+// module.exports = mongoose.model('User2', User2)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// const userSchema = new Schema({ name: String, type: String });
|
|
|
+// userSchema.index({ name: 1, type: -1 });
|
|
|
+// console.log(User2);
|
|
|
+
|
|
|
+// userSchema.methods.findSimilarTypes = function(cb) {
|
|
|
+// return this.model('User2').find({ type: this.type }, cb);
|
|
|
+// };
|
|
|
+
|
|
|
+// const User2 = mongoose.model('User2', userSchema);
|
|
|
+// const user = new User2({ type: 'dog' });
|
|
|
+
|
|
|
+// dog.findSimilarTypes(function(err, dog) {
|
|
|
+// console.log(dog); // woof
|
|
|
+// });
|
|
|
+
|
|
|
+const mongoose = require('mongoose')
|
|
|
+
|
|
|
+const userSchema = mongoose.Schema({
|
|
|
+ name: String,
|
|
|
+ email: String,
|
|
|
+ age: Number
|
|
|
+})
|
|
|
+
|
|
|
+const User = mongoose.model('User', userSchema)
|
|
|
+
|
|
|
+module.exports = User;
|
|
|
+
|
|
|
+const user = new User({name: 'Alex', email:'a@sss', age: 34})
|
|
|
+console.log('user', user);
|
|
|
+
|
|
|
+user.save((err, user) => {
|
|
|
+ if (err) {
|
|
|
+ console.log('err', err)
|
|
|
+ }
|
|
|
+ console.log('saved user', user)
|
|
|
+ });
|
|
|
+
|
|
|
+User.findById('59d8acf4ce867b292ddb815e', (err, user) => {
|
|
|
+ console.log('result', err, user)
|
|
|
+ });
|