referencing in FromArray
Closed this issue · 5 comments
Hello, is it possible to use a reference to a FromArray?
If I see this correctly, only the type object is possible in the documentation.
This would be super helpful to link accounts with randomly generated data.
Hi @adrian-goe, the documentation is a bit misleading, actually a the content of a "fromArray" can be anything: int, string, objectID...
for example, this is should work fine: ( mongoplayground.net/p/drVXEIX3whA )
[
{
"collection": "collection",
"count": 10,
"content": {
"k": {
"type": "fromArray",
"in": [
3,
12,
5363
]
}
}
}
]
What are you trying to achieve exactly ?
I have 2 collections.
collection a withIch habe 2 Sammlungen
Sammlung a beinhaltet unteranderem diesen Teil:
"partnerId": {
"type": "ref",
"id": 1000,
"refContent": {
"type": "objectId"
}
},
And then have ic collection b with the login data to be associated with its partnerId.
But the whole thing is stored as an object:
"linkedPartner": {
"type": "fromArray",
"in": [
{
"confirmed": true,
"partnerId": "5ddd5ef88c545922857cefa7"
},
So what i want is something like this:
"linkedPartner": {
"type": "fromArray",
"in": [
{
"confirmed": true,
"partnerId": {
"type": "ref",
"id": 1000
},
},
I use the fromArray here so that I can use the same login data as test data over and over again. But for the test data it doesn't matter which partnerId is linked there.
Maybe there is a better way.
@adrian-goe maybe something like this : mongoplayground.net/p/XGi6544IH7S ?
[
{
"collection": "a",
"count": 3,
"content": {
"partnerId": {
"type": "ref",
"id": 1,
"refContent": {
"type": "objectId"
}
}
}
},
{
"collection": "b",
"count": 3,
"content": {
"linkedPartner": {
"type": "object",
"objectContent": {
"partnerId": {
"type": "ref",
"id": 1
},
"confirmed": {
"type": "boolean"
}
}
}
}
}
]
this will work, but its not beautiful for many users
Never mind. I saw my mistake.
Thanks for the help :-)