簡體   English   中英

MongoDB:如何使用Java驅動程序獲取包含數組的所有元素?

[英]MongoDB : how to get all elements that contain an array using Java Driver?

您將如何使用Java驅動程序編寫此MongoDB查詢:

db.customers.find({'arrayName':{$ exists:true},$ where:'this.arrayName.length> 0'})

干杯,揚

要使用Java驅動程序構建查詢,您可以將所有Javascript對象替換為DBObject

DBObject condition = new BasicDBObject();
condition.put("arrayName", new BasicDBObject("$exists", true));
condition.put("$where",  "this.arrayName.length>0");

DBCursor result = yourDatabase.getCollection("customers").find(condition);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM