#1 2018-07-10 10:15:34

nexgis
Member
Registered: 2017-10-26
Posts: 2

GetValueByPath function (from SynCommons) with array elements

Hey!

I've recently tried to use "GetValueByPath" and "GetPVariantByPath" to access an element in a nested array using something similar to

  _Safe(MongoDocument).GetValueByPath("arrayField.4");

where the element itself is a document.
This kind of path reference seems to be fully supported in Mongo 3

I seem to get a fake Variant and when looking at the source the function seems to exit if the Variant is not a DocVariant of some kind.
Am I correct in assuming this syntax is not supported?

Is there an appropriate way to access array elements in such a style?
Thank you very much in advance!

Offline

#2 2018-07-10 11:54:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: GetValueByPath function (from SynCommons) with array elements

Which syntax are your talking about?

Offline

#3 2018-07-10 12:47:41

nexgis
Member
Registered: 2017-10-26
Posts: 2

Re: GetValueByPath function (from SynCommons) with array elements

Sorry I did not make it clear.

I mean accessing an array element by index, as per the example in the Mongo documentation https://docs.mongodb.com/manual/tutorial/query-arrays/.

For example, if I have a document, which has a field of type array, called "arrayField" and I want to access the second element, then in Mongo I could write the name followed by a dot and then index.

This is the syntax I assumed I could do:

"arrayField.1"

I assumed I would be able to access the document as a Variant by typing

var ParentDocument: Variant;
     DocumentINeed: Variant;
...
begin
  DocumentINeed := _Safe(ParentDocument).GetValueByPath('arrayField.1');
end;

I hope this makes it clear.

Offline

Board footer

Powered by FluxBB