DBObject todayWLCriteria = new BasicDBObject(); todayWLCriteria.put("shop_id", utilsService.getAtb(request).getShopId()); todayWLCriteria.put("sale_channel", "$in:[1,2,3,4]}"); //这里该如何传值 List<DBObject> todayWLObjects = mongoPersist.getMongoCollection(RtSellerRegion_h).find(todayWLCriteria).sort(new BasicDBObject("no", -1)).toArray();
来查询mongo中的数据,但是sale_channel 中需要传入四个值1,2,3,4
我知道直接在Mongo 中可以使用$in来查询,像这样db.tianyc02.find({age:{$in:[11,22]}})
但是,在java中的OBject对象中,我该怎么把这个四个值传入sale_channel中,我代码中写的那样程序无法正确查询,求大神指教。
好吧,等了这么久都没人来回答,经过长时间度娘谷哥,终于搞定,现在贴上解决方法如下:
MongoDB Plugin可能java上最好用而且实时跟进官方版本的ORM,让您更加舒适地使用MongoDB。
强烈推荐 https://www.oschina.net/p/mongodb-plugin
使用plugin一个in(数组)就可以达到你的目的了