Getting a Database object is easy once you have a Connection instance.In most cases, keeping a # reference to the Database object for the lifetime of your program should # be sufficient.Let us imagine we have a collection called users, containing all the users of our game.Each user has a username, a first name, surname, date of birth, email address and a score.This has the advantage of being very lightweight, but can occasionally cause problems due to typos.These can be hard to track down unless you have good test coverage.# dbh.usrs is a typo, we mean dbh.users!You might be left scratching your head wondering why your user document isn’t there.We recommend being extra vigilant to double check your spelling when addressing collections.Good test coverage can also help find bugs of this sort.It is considered to be the primary key for that document, and is expected to be unique unless the collection has been explcitly created without an index on _id.Write to a Collection Safely and Synchronously
Sponsored
Typically you create one once, and then forget about it.
Posted 2023-01-27 17:16:24
0
541
Sponsored