This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const docToUpdate = { name: 'Halo MCC' }; | |
| const updateTerm = { $set: { name: 'Halo Master Chief Collection' } }; | |
| console.log('Before update :'); | |
| let haloMcc = await db.collection('games').findOne(docToUpdate); | |
| console.log(haloMcc); | |
| await updateDoc(db, docToUpdate, updateTerm); | |
| // check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // filter | |
| const filter = { | |
| name: 'Red Dead Redemption 2', | |
| platform: 'XBOXONE' | |
| }; | |
| await deleteDoc(db, filter); | |
| const deleteDoc = async(db, filter) => { | |
| try { | |
| await db.collection('games').findOneAndDelete(filter); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let adder = DoubleAdder() | |
| print(adder.add(a: 34.67, b: 89.23)) // 123.9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DoubleAdder: Adder { | |
| typealias Number = Double | |
| func add(a: Double, b: Double) -> Double { | |
| return a + b | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func add(a: Double, b: Double) -> Double { | |
| return a + b | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DoubleAdder: Adder { | |
| typealias Number = Double | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol Adder { | |
| associatedtype Number | |
| func add(a: Number, b: Number) -> Number | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let adder = IntAdder() | |
| print(adder.add(a: 55, b: 45)) // prints 100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class IntAdder: Adder { | |
| func add(a: Int, b: Int) -> Int { | |
| return a + b | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol Adder { | |
| func add(a: Int, b: Int) -> Int | |
| } |