mongodb insert value in array code example

Example: F# mongodb insert to array

type FriendModel = {
        Name : string
        Phone : string
    }
    type PersonModel = {
        Name : string
        Friends: FriendModel list
    }

    let insertNewFriend (personName:string) (newFriend:FriendModel) = 
        let filter = Builders<PersonModel>.Filter.Eq((fun x -> x.Name), personName)
        let fields = StringFieldDefinition<PersonModel>("Friends")
        let updateDefinition = Builders<PersonModel>.Update.Push(fields,{Name="Mahdi";Phone="+1"})
        collections.UpdateOne(filter,updateDefinition)

Tags:

Misc Example