MongoTemplate查詢 Criteria對象表明的是查詢條件

Criteria對象表明的是查詢條件sql

 

一、舉例說明 spa

     (1)mongo sql 對應關係:對象

              db.users.find({name:"suns"});                 -------->Criteria criteria=new Criteria("name");it

                                                                                                                criteria.is("suns");查詢

     (2)兩個查詢條件:db

               db.users.find({name:"suns",_id:22});----------->Criteria  criteria=new Criteria("name");co

                                                                                                                 criteria.is("suns");new

                                                                                                                 criteria.and("_id").is(22);

      (3)條件複雜(age>10)

               db.users.find({age:{$gt:10:}});           ------------>Criteria criteia=new Criteria("age");

                                                 criteria.gt("10");//若是是大於等於10,那麼再添加一句話:criteria.and("age").is("10");便可

相關文章
相關標籤/搜索