简体   繁体   English

使用java查找包含mongodb中特定值的数组的文档

[英]Find documents with array that contains a specific value in mongodb using java

According to the answer provided in this link: Find document with array that contains a specific value , i have tried getting the items in java using this statement 根据此链接提供的答案: 查找包含特定值的数组的文档 ,我尝试使用此语句获取java中的项目

searchQuery.put("arrayMine", new BasicDBObject("$in","[xxx]"));
OR
searchQuery.put("arrayMine", new BasicDBObject("$in","xxx"));

But it keeps saying the $in value must be an array while my arrayMine is an array. 但它一直说$ in值必须是一个数组,而我的arrayMine是一个数组。 What should be the correct syntax in java? java中正确的语法应该是什么?

Both variants you have are treating the value of BasicDBObject as String . 您拥有的两种变体都将BasicDBObject的值视为String

Use 采用

searchQuery.put("arrayMine", new BasicDBObject("$in",Arrays.asList("xxx"))        

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java mongodb 3.0:在内部文档数组中查找值 - java mongodb 3.0: find value in internal array of documents MongoDB 如何查找数组中包含特定字符串的所有文档? - MongoDB how to find all documents who's array contains a specific string? 使用Java查找包含具有特定值的字段的所有mongo文档 - Find all mongo documents containing a field with a specific value using java 如何使用RestHighLevelClient查找具有特定字段的文档包含字符串 - How to find documents with specific field contains string using RestHighLevelClient 如何使用Java驱动程序在MongoDB中更新数组的嵌入式文档中的字段值 - How to Update fields value in embedded documents of an Array in MongoDB using Java Driver 使用Java驱动器在mongoDB中创建一个包含paired_value(键及其值)集的数组 - Create an array which contains set of paired_value (key and its value) in mongoDB using java Drive Mongodb和Java:查找包含在数组字段中的具有指定值的文档 - Mongodb and Java: finding documents with a specified value contained in an array field 使用Java更新数组中的嵌入式文档,而无需在MongoDb中重复 - Update Embedded Documents in array without Repeating in MongoDb using Java 使用Java将JSON文档数组插入MongoDB时出错 - Error while inserting an array of JSON documents in to MongoDB using Java 使用Java驱动程序从MongoDB中的数组中检索一组文档 - Retrive a set of documents from array in MongoDB using Java driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM