Commit c2628d35 authored by nontawat kanboon's avatar nontawat kanboon

Delete logic.js

parent ccc4ca5c
let lo = function toLower(y) {
return y.toLowerCase();
}
//mongoose.assert=require
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const db = mongoose.connect('mongodb://localhost:27017/contactdb');
const contactSchema = mongoose.Schema({
firstname: { type: String, set: toLower },
lastname: { type: String, set: toLower },
phone: { type: String, set: toLower },
email: { type: String, set: toLower }
});
const Contact = mongoose.model('Contact', contactSchema);
const addContact = (contact) => {
console.info('กำลังเพิ่มรายการติดต่อ ${contact}');
Contact.create(contact, (err) => {
// assert.equal(null, err);
console.info('เพิ่มรายการตืดต่อใหม่สำเร็จ');
db.disconnect();
});
};
const getContact = (name) => {
const search = new RegExp(name, 'i');
Contact.find({$or: [{firstname: search }, {lastname: search }]})
.exec((err, contact) => {
//assert.equal(null, err);
console.info(contact);
console.info(ค้นหาเจอทั้งหมด ${contact.length} รายการ);
db.disconnect();
});
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment