I am trying to extract JSON document subtree that's indexed by numerical key.
My JSON string:
{
"pk": 20,
"tree": {
"100": {
"values": [
1, 2, 3
]
},
"abc" => 999
}
}
My code:
$session = mysql_xdevapi\getSession("mysqlx://root:letmein@localhost");
$schema = $session->getSchema('test');
$coll = $schema->getCollection('myColl');
$expr = mysql_xdevapi\Expression('$.tree.*');
$result = $coll->find('$.pk=20')->fields(['$.tree[100]'])->execute();
Using '$.tree[100]' results in
[
'tree' => null
]
Using '$.tree.*' results in
[
'tree' => [
0 => [
1, 2, 3
],
1 => 999
]
]
Using '$.tree.abc' results in
[
'tree' => [
'abc' => 999
]
]
So, '$.tree.abc' works, but '$.tree[100]' doesnt.
Question. How can I access values key using '$.tree[100]' expression?
Thanks!
... $coll->find('$.pk=20')->fields(['$.tree."100"'])->execute();.mysqlsh-js> db.myColl.find("pk = 20").fields("tree.'100'");.