FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard. For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions. |
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:
[
{
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'}}]
[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]]
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))))
[{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"
}
}
]
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!