0

I am trying to find a document with an array of tags which match a list of values, using the MongoDB's $all function through Spring Data MongoDB API for all().

Tag is a embedded document with two fields: type and value.

I am not sure what kind of Java type to pass in to the method as it accepts an array of Objects, tried to pass in an array of Criteria objects into the the function but the output is below:


Query: { "tags" : { "$all" : [ { "$java" : org.springframework.data.mongodb.core.query.Criteria@5542c4fe }, { "$java" : org.springframework.data.mongodb.core.query.Criteria@5542c4fe } ] } }, Fields: { }, Sort: { }

How should I proceed?

I want to achieve the following:

db.template.find( { tags: { $all: [ {type:"tagOne", value: "valueOne"}, {type:"tagTwo", value: "valueTwo"} ] } } )

Edited for clarity:

The code which I used is similar to:

Query query = new Query(baseCriteria.and("tags").all( criteriaList.toArray()))

The criteria list is formed by:

            Criteria criteria = new Criteria();
            criteria.and("type").is(tag.getType()).and("value").is(tag.getValue());
            criteriaList.add(criteria);
0

1 Answer 1

0

OK, I've just found out, the Java type required is org.bson.Document, which you can get using:

criteria.getCriteriaObject()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.