Welcome.
Creating a Database
To create a database in MongoDB, start by creating a MongoClient object, then specify a connection URL with the correct ip address and the name of the database you want to create.
MongoDB will create the database if it does not exist, and make a connection to it.
Creating a Table
To create a table in MongoDB, use the
createCollection() method:Insert Into Table
To insert a record into a table in MongoDB, we use the
insertOne() method.
The first parameter of the
insertOne() method is an object containing the name(s) and value(s) of each field in the record you want to insert.
It also takes a callback function where you can work with any errors, or the result of the insertion:
Select One
To select data from a table in MongoDB, we can use the
findOne() method.
The
findOne() method returns the first occurrence in the selection.
The first parameter of the
findOne() method is a query object. In this example we use an empty query object, which selects all records in a table (but returns only the first record).
No comments:
Post a Comment