func (s *MongoSuite) TestQuery_FindByFoo(c *C) { store := NewMyModelStore(s.db) m := store.New() m.String = "foo" c.Assert(store.Insert(m), IsNil) q := store.Query() q.AddCriteria(operators.Eq(Schema.MyModel.String, "foo")) r, err := store.Find(q) c.Assert(err, IsNil) res, err := r.All() c.Assert(res, HasLen, 1) c.Assert(err, IsNil) q.AddCriteria(operators.Eq(Schema.MyModel.String, "bar")) r, err = store.Find(q) c.Assert(err, IsNil) one, err := r.One() c.Assert(one, IsNil) c.Assert(err, IsNil) }
func (q *ProductQuery) FindById(id bson.ObjectId) { q.AddCriteria(operators.Eq(storable.IdField, id)) }