You are right, you have to create the properties before to use %FindDocuments...BUT...it doesn't work for arrays of data. I've found this answer to a similar question:
https://community.intersystems.com/post/how-query-data-docdb-through-py…
I was testing the behaviour with this example:
DO db.%CreateProperty("type","%String","$.PhoneNumber.type")
SET dynAbObj = {
"FullName":"John Smith",
"FirstName":"John",
"Address":{
"street":"101 Main Street",
"city":"Mapleville",
"state":"NY",
"postal code":10234
},
"PhoneNumber":
[
{"type":"home","number":"212-456-9876"},
{"type":"cell","number":"401-123-4567"},
{"type":"work","number":"212-444-5000"}
]
}
$$$TRACE(dynAbObj.%ToJSON())
SET jstring = dynAbObj.%ToJSON() // dynamic abstract object to JSON string
DO db.%FromJSON(jstring) // JSON string inserted into document database
$$$TRACE(db.%FindDocuments(["type","cell","="]).%ToJSON())
$$$TRACE(db.%FindDocuments(["type","home","="]).%ToJSON())This is the answer for the first search:
{"sqlcode":100,"message":null,"content":[]}And this is the answer for the second search:
{"sqlcode":100,"message":null,"content":[{"%Doc":"{\"FullName\":\"John Smith\",\"FirstName\":\"John\",\"Address\":{\"street\":\"101 Main Street\",\"city\":\"Mapleville\",\"state\":\"NY\",\"postal code\":10234},\"PhoneNumber\":[{\"type\":\"home\",\"number\":\"212-456-9876\"},{\"type\":\"cell\",\"number\":\"401-123-4567\"},{\"type\":\"work\",\"number\":\"212-444-5000\"}]}","%DocumentId":"1","%LastModified":"2023-09-18 10:13:30.694"}]}As you can see, it only works fine for the first value of the array, the definition of the property doesn't allow to define an array of values.
- Log in to post comments

.png)