Tag: mongodb query

使用Morphia返回匹配的数组元素

我正在寻找一种方法,在提供一些conditions后过滤掉给定List of Object所有对象。 例如 A级 @Entity(value = “tbl_A”) public class A { private String notes; @Embedded private List sampleObject; ….getter and setter … } B级 @Embedded public class SampleObject { private boolean read; private boolean sentByBot; … getter and setter … } 现在,我只想收集已将sentByBot参数设置为true sentByBot 。 我使用以下方法: Query queryForA = datastore.find(A.class); queryForA.field(“sampleObject.sentByBot”).equal(false).retrievedFields(true, “sampleObject.sentByBot”); 上面的代码给出了包含sampleObject.sentByBot true和false的objects的完整列表。 我也尝试filter方法即 […]

如何使用Java在MongoDB中使用AND和OR子句执行查询

我想在MongoDB 3.2中使用Java Driver 3.2执行查询,它同时包含$and和$or子句。 通过参考 ,我尝试了以下方法: List criteria1 = new ArrayList(); List criteria2 = new ArrayList(); criteria1.add(new Document(“fetchStatus”, new Document(“$gte”, FetchStatus.PROCESSED_NLP.getID()))); criteria1.add(new Document(“fetchStatus”, new Document(“$lte”, fetchStatusParam))); criteria1.add(new Document(“episodeID”, new Document(“$in”, episodeIDs))); criteria2.add(new Document(“fetchStatus”, new Document(“$eq”, PROCESSED_FETCH.getID()))); criteria2.add(new Document(“isFullTextRet”, new Document(“$eq”, false))); BasicDBList or = new BasicDBList(); or.add(criteria1); or.add(criteria2); DBObject query = new BasicDBObject(“$or”, or); ArrayList […]

mongotemplate聚合与条件

我有一个文件看起来像这样的集合: { _id: “545b9fa0dd5318a4285f7ce7”, owner: “admin”, messages: [ { id: “100”, status: “sent”, note: “” }, { id: “100”, status: “pending”, note: “” }, { id: “101”, status: “sent”, note: “” }, { id: “102”, status: “sent”, note: “” }, { id: “101”, status: “done”, note: “” } ] } (这只是一个简短的例子,在我的例子中,子数组非常大) 我需要查询集合并获取特定文档的一些统计信息。 所以在这个例子中,如果我查询具有id:“545b9fa0dd5318a4285f7ce7”的doucment,我应该得到这个结果: { sent: […]

Java MongoDB 3.0驱动程序查询不带filter

我如何使用Java MongoDB 3.0驱动程序查询不同的内容? 我试图从MongoDB中的位置集合查询唯一类别记录。 在Mongo shell中,这很简单: db.locations.distinct(“categories”); 在Java中,它不一样。 MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase(“yelp”); //this will not compile, although examples from before 3.0 do it this way MongoCursor c = db.getCollection(“locations”).distinct(“categories”).iterator();

如何查找符合多个条件的文档

我正在尝试使用操作数AND’d一起查询集合。 我有shell版本工作: db.widgets.find({color: ‘black, shape: ’round’, weight: 100}) 我无法找到Java等价物(使用本机驱动程序 )。 我尝试了各种各样的东西,但这是我最近的尝试: // Find all black, round widgets with weight 100 List criteria = new ArrayList(); criteria.add(new BasicDBObject(“color”, “black”)); criteria.add(new BasicDBObject(“shape”, “round”)); criteria.add(new BasicDBObject(“weight”, 100)); DBCursor cur = widgets.find(new BasicDBObject(“$and”, criteria)); // Get all matching widgets and put them into a list List widgetList = new […]

在mongodb聚合中查找

以下bson是personaddress集合: { “id” : “123456”, “name” : “foo”, “address” : [ { “local” : “yes”, “location” : [ { “place” : { “_id”:”VZG”, }, “place_lat” : “18”, “place_lan” : “83”, }, { “place” : { “name” : “kerala”, “district” : “palakkad”, “pincode” : “5203689”, }, “place_lat” : “18”, “place_lan” : “83”, } ] } ] […]

如何在mongo中插入日期文件?

我们正在尝试插入一个包含当前日期的文档作为其字段。 我们使用eclipse插件为mongodb编写java。 我们想要执行mongo的Date()命令来从mongo而不是从java获取日期。 我该如何执行这个mongo查询? db.example.insert({“date”:new Date()}) 我在预览问题中发现了这个问题,但答案没有帮助 链接