I am trying to run this query
{campaignId: ObjectId('5a6b11e806f0252e1408e379'),'options.path': 'NT'}
it works perfectly in Compass, but when I try to add in MongoRepository interface like below:
@Query("{ 'campaignId': ObjectId(?0), 'options.path': ?1})")
public Dialog findByCampaignIdAndPath(String campaignId, String path);
I get this exception:
nested exception is com.mongodb.util.JSONParseException:
@Query("{ 'campaignId': ObjectId(?0), 'options.path': ?1})")
Using spring-boot version 1.5.9.RELEASE, not the buggy version
EDIT1: specified the exact id name, as suggested in comments
EDIT2: Here is my Dialog class
@Getter
@Setter
@Document(collection = "Dialog")
public class Dialog {
@Id
public String id;
private DBRef campaignId;
private Message message;
private List<Option> options;
public Dialog(final Message message, final List<Option> options) {
this.message = message;
this.options = options;
}
}
Try this:
@Query("{ 'campaignId': ?0, 'options.path': ?1}")
public Dialog findByIdAndPath(String id, String path);
Or Simply:
public Dialog findByCampaignIdAndOptionsPath(String id, String path);
If Option
is an embedded document
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With