💥Database Created
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.💥Creating a Table
To create a table in mongodb use the creteCollection()
💥 Insert Into Table
To insert a record into a table in MongoDbB, We use the insertOne()
.
💥Select One
To select data from a table in MongoDB we can use the findOne()
💥Node.js MongoDB Query
When selecting records from a table, you can filter the result by using a query object.
We can use find() method for limit the search
💥Node.js MongoDB Remove
Delete Record
We can use remove() command to delete records or documents in Node.js MongoDB
💥Drop Collection
we use drop() methode for to delete a table or collection in node.js MongoDB
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/mydb";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
db.dropCollection("customers", function(err, delOK) {
if (err) throw err;
if (delOK) console.log("Table
deleted");
db.close();
});
});
Save and run this file we get the message "table deleted"
No comments:
Post a Comment