Can I place pointer (as value for some key) inside field with object type?

I need a field, that contains one pointer. Pointer type is not suitable cuz pointer may be for different entities, so I thought about Array or Object. For me it will be no matter which except theoretical performance when search by this field.

As to Array - it’s simple, I can see in a dashboard pointer as object with type pointer and className.
But in case with Object field - there is only key objectId:
{ "pointerKey": { "objectId": "gmMepz8C06" } }

So pointers only for Pointer, Array or relations?

If for search query with Object I could use
equalTo('fieldName.pointerKey', pointer)
then what can I use with Array - equalTo('fieldName', [pointer]) ?
May be 'fieldName[0]'?

I’d go with an object column. You can have something like this stored in each of your rows:

{ "className": "SomeClass", "objectId": "someobjectid" }

, then you can find using:

query.equalTo('fieldName.className','SomeClass'')
query.equalTo('fieldName. objectId','someobjectid'')
1 Like

Has it any advantages before using Array field?

Or before

query.equalTo('fieldName', { "className": "SomeClass", "objectId": "someobjectid" })

Is that matter of performance?

I am not sure regarding the performance but I believe both queries will have about the same performance. I suggested object (and not array) because I understood you needed to store only one pointer per row. You can use array as well and these queries should also work.

In mongo we can do

The following example queries for all documents where tags is an array that contains the string "red" as one of its elements:

const cursor = db.collection('inventory').find({ tags: 'red' });

May be with array field in parse query I can use something like this
equalTo('fieldName', pointer)
instead of equalTo('fieldName', [pointer]) or equalTo('fieldName.0', pointer)

Yes. You can do

equalTo('fieldName', pointer)
1 Like

Take a look at this doc: https://docs.parseplatform.org/js/guide/#using-an-array

You will probably not be able to use the include because you will have pointers to different classes, but the other features should work for your case.

1 Like