You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a database index on a field where the values are an array, it is not possible to find the document using an exact document template, you'll need to specify an $all option.
Example java code:
InMemoryMongoServer server = new InMemoryMongoServer();
server.bind();
MongoClient mongoClient = new MongoClient(new ServerAddress(server.getLocalAddress()));
MongoDatabase db = mongoClient.getDatabase("db");
MongoCollection<Document> collection = db.getCollection("coll");
collection.createIndex(new Document("key", 1), new IndexOptions().unique(true));
collection.insertOne(new Document("key", Arrays.asList("val1", "val2")));
// search for { "key" : [ "val1", "val2" ]}
FindIterable<Document> documents = collection.find(new Document("key", Arrays.asList("val1", "val2")));
List<Document> collect = StreamSupport.stream(documents.spliterator(), false).collect(Collectors.toList());
// no entries found
System.out.println(collect);
// search for { "key" : { "$all" : [ "val1", "val2" ]}}
documents = collection.find(new Document("key", new Document("$all", Arrays.asList("val1", "val2"))));
collect = StreamSupport.stream(documents.spliterator(), false).collect(Collectors.toList());
// finds the document
System.out.println(collect);
According to the mongo documentation, I'd expect the first query to also return the document, which is also the case if I skip the index creation.
A long shot guess is that the code handling index updates maybe also should create an entry for the array data as well?
Thanks for a great tool by the way!
The text was updated successfully, but these errors were encountered:
Given a database index on a field where the values are an array, it is not possible to find the document using an exact document template, you'll need to specify an
$all
option.Example java code:
According to the mongo documentation, I'd expect the first query to also return the document, which is also the case if I skip the index creation.
A long shot guess is that the code handling index updates maybe also should create an entry for the array data as well?
Thanks for a great tool by the way!
The text was updated successfully, but these errors were encountered: