0

I want to use a MySQL database to manage a collection of documents in JSON format. Let's say each document has this structure:

{ 
  "firstname":"John",
  "lastname":"Smith",
  "books":[
    { "title":"Dune", "author":"Frank Herbert" },
    { "title":"Fahrenheit 451", "author":"Ray Bradbury" }
  ]
}

How would I use X DevAPI to find documents where the "books" array contains a specific title?

KarlKEP
  • 11
  • 2

1 Answers1

0

You can use a SearchConditionStr containing a documentPathLastItem expression in form of <the_title> in $.books[*].title (the leading $. should be optional), which depending on the language you are using will end up being something like:

collection.find(':name in books[*].title')
  .bind('name', '<the_title>')
  .execute()

Disclaimer: I'm the lead developer of the MySQL X DevAPI Connector for Node.js

ruiquelhas
  • 1,905
  • 1
  • 17
  • 17