Shibin Raju Mathew
Shibin Raju Mathew

Reputation: 930

How to select documents by checking array elements in mongodb and spring criteria

I have the following document

{ "std_name": "Abcd", "tags": ["tag1", "tag2", "tag3"] },
{ "std_name": "Wxyz", "tags": ["tag4", "tag1", "tag3"] },
{ "std_name": "Demoname", "tags": ["tag4", "tag2", "tag3"] },

where i have to select all documents with tag2 i tried with criteria as follow but returns null

1.Criteria.where("tags").is("tag2")

2.Criteria.where("tags").all("tag2")

how to get the result.

Upvotes: 0

Views: 40

Answers (1)

Nishant Bhardwaz
Nishant Bhardwaz

Reputation: 1001

You can use in function to select all document having tag2.

Criteria.where("tags").in(Arrays.asList("tag2"));

Upvotes: 1

Related Questions