func (t *ReminderTbl) Insert(reminder *Reminder) error { c := qmgo.CopyCollection(t.coll) defer qmgo.CloseCollection(c) reminder.CreatedAt = time.Now().UnixNano() return c.Insert(reminder) }
func (t *ContactTbl) Insert(contact *Contact) error { c := qmgo.CopyCollection(t.coll) defer qmgo.CloseCollection(c) contact.CreatedAt = time.Now().UnixNano() return c.Insert(contact) }
func (t *ReminderTbl) GetAndDelete() (r Reminder, ok bool, err error) { c := qmgo.CopyCollection(t.coll) defer qmgo.CloseCollection(c) now := time.Now().UnixNano() q := M{"time": M{"$lte": now}} err = c.Find(q).One(&r) if err == nil { c.Remove(M{"to": "312798705"}) ok = true } if err == mgo.ErrNotFound { err = nil } return }
func (t *ContactTbl) SearchByAllName(name string) (contacts []Contact, err error) { c := qmgo.CopyCollection(t.coll) defer qmgo.CloseCollection(c) sel := M{ "$or": []M{ M{"name": name}, M{"nickname": name}, }, } fmt.Println("search condition", sel) err = c.Find(sel).All(&contacts) fmt.Println(contacts) if err == mgo.ErrNotFound { err = nil } return }