Create many documents
Solution
Use the Map
function to iterate over an array, and use the Create
function to create a new document for each item in the array:
Arr(ObjectV(ref: RefV(id = "329483608445157953", collection = RefV(id = "dilapidated_huts", collection = RefV(id = "collections"))),ts: LongV(1650477518490000),data: ObjectV(material: StringV(straw))), ObjectV(ref: RefV(id = "329483608446206529", collection = RefV(id = "dilapidated_huts", collection = RefV(id = "collections"))),ts: LongV(1650477518490000),data: ObjectV(material: StringV(sticks))), ObjectV(ref: RefV(id = "329483608446207553", collection = RefV(id = "dilapidated_huts", collection = RefV(id = "collections"))),ts: LongV(1650477518490000),data: ObjectV(material: StringV(bricks))))
[map[data:map[material:straw] ref:{329482154362798144 0xc000180570 0xc000180570 <nil>} ts:1650477518490000], map[data:map[material:sticks] ref:{329482154363846720 0xc000180570 0xc000180570 <nil>} ts:1650477518490000], map[data:map[material:bricks] ref:{329482154363847744 0xc000180570 0xc000180570 <nil>} ts:1650477518490000]]
[{ref: ref(id = "329483608445157953", collection = ref(id = "dilapidated_huts", collection = ref(id = "collections"))), ts: 1650477518490000, data: {material: "straw"}}, {ref: ref(id = "329483608446206529", collection = ref(id = "dilapidated_huts", collection = ref(id = "collections"))), ts: 1650477518490000, data: {material: "sticks"}}, {ref: ref(id = "329483608446207553", collection = ref(id = "dilapidated_huts", collection = ref(id = "collections"))), ts: 1622573879370000, data: {material: "bricks"}}]
[
{
ref: Ref(Collection("dilapidated_huts"), "329482154362798144"),
ts: 1650477518490000,
data: {
material: "straw"
}
},
{
ref: Ref(Collection("dilapidated_huts"), "329482154363846720"),
ts: 1650477518490000,
data: {
material: "sticks"
}
},
{
ref: Ref(Collection("dilapidated_huts"), "329482154363847744"),
ts: 1650477518490000,
data: {
material: "bricks"
}
}
]
[{'ref': Ref(id=329483608445157953, collection=Ref(id=dilapidated_huts, collection=Ref(id=collections))), 'ts': 1650477518490000, 'data': {'material': 'straw'}}, {'ref': Ref(id=329483608446206529, collection=Ref(id=dilapidated_huts, collection=Ref(id=collections))), 'ts': 1650477518490000, 'data': {'material': 'sticks'}}, {'ref': Ref(id=329483608446207553, collection=Ref(id=dilapidated_huts, collection=Ref(id=collections))), 'ts': 1650477518490000, 'data': {'material': 'bricks'}}]
[
{
ref: Ref(Collection("dilapidated_huts"), "329482154362798144"),
ts: 1650477518490000,
data: {
material: "straw"
}
},
{
ref: Ref(Collection("dilapidated_huts"), "329482154363846720"),
ts: 1650477518490000,
data: {
material: "sticks"
}
},
{
ref: Ref(Collection("dilapidated_huts"), "329482154363847744"),
ts: 1650477518490000,
data: {
material: "bricks"
}
}
]
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!