Пример #1
0
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)
}
Пример #2
0
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)
}
Пример #3
0
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
}
Пример #4
0
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
}