如何在 mongodb 中使用 $and 运算符 - java 驱动程序 [英] How to use $and operator in mongodb - java driver
本文介绍了如何在 mongodb 中使用 $and 运算符 - java 驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何使用逻辑 AND($and) 查询 mongo,
How do we query for mongo using logical AND($and),
示例:合集:主题
从收集主题我需要得到所有满足条件的记录,
From collection subject I need to get all the records satisfying the condition,
总分!=10 和总分!=15.
totalmarks!=10 and totalmarks!=15.
推荐答案
相当于 java 驱动程序.
Equivalent in java driver.
List<DBObject> criteria = new ArrayList<DBObject>();
criteria.add(new BasicDBObject("totalmarks", new BasicDBObject("$ne", 10)));
criteria.add(new BasicDBObject("totalmarks", new BasicDBObject("$ne", 15)));
DBCursor dbCursor = collection.find(new BasicDBObject("$and", criteria));
这篇关于如何在 mongodb 中使用 $and 运算符 - java 驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文