Create Many
The CreateMany
method is used to insert multiple documents into a collection.
Usage
witchers := WitcherModel.CreateMany([]Witcher{
{
Name: "Geralt of Rivia",
Age: 100,
Occupation: "Witcher",
Weapons: []string{"Silver Sword", "Steel Sword"},
Retired: false,
School: nil
},
{
Name: "Yennefer of Vengerberg",
Age: 100,
Occupation: "Sorceress",
Weapons: nil,
Retired: false,
School: nil
},
}).ExecTT()
for _, witcher := range witchers {
fmt.Println(witcher.ID) // The ObjectID of the newly created document
fmt.Println(witcher.CreatedAt) // The timestamp when the document was created
fmt.Println(witcher.UpdatedAt) // The timestamp when the document was last updated
}
InsertMany
The InsertMany
method is an alias for the CreateMany
method and can be used interchangeably.