Movatterモバイル変換


[0]ホーム

URL:


ShahDhruv21, profile picture
Uploaded byShahDhruv21
PPTX, PDF115 views

MongoDB installation,CRUD operation & JavaScript shell

This document provides an overview of MongoDB, including how to install it, perform CRUD operations, and use the MongoDB JavaScript shell. It discusses MongoDB's document-oriented data model and how it is suited for modern applications. Installation instructions for Windows are included, as well as examples of inserting, querying, updating, and deleting documents using MongoDB methods. The document also covers how to connect to MongoDB and run scripts from the JavaScript shell.

Embed presentation

Download to read offline
A. D. Patel Institute Of TechnologyBig Data and Analytics [2171607] : A. Y. 2019-20Installing MongoDB , Querying through MongoDB &MongoDB through JavaScript ShellPrepared By :Dhruv V. Shah (160010116053)B.E. (IT) Sem - VIIGuided By :Dr. Narendra Chauhan(Head Of IT Dept. , ADIT)Department Of Information TechnologyA.D. Patel Institute Of Technology (ADIT)New Vallabh Vidyanagar , Anand , Gujarat1
Outline Introduction Why Use MongoDB ? & What is MongoDB great for? MongoDB : CAP Approach. Steps for MongoDB Installation MongoDB CRUD Operations MongoDB through JavaScript Shell References2
Introduction What is MongoDB ? MongoDB is a general purpose, document-based, distributed database built for modernapplication developers and for the cloud era. MongoDB is a document database, which means it stores data in JSON-like documents (calledBSON [Binary JavaScript Object Notation]). It falls under the category of a NoSQL database. MongoDB is Scalable High-Performance Open-source, Document-orientated database. Built for Speed. Rich Document based queries for Easy readability. Full Index Support for High Performance. Replication and Failover for High Availability. Auto Sharding for Easy Scalability. Map / Reduce for Aggregation.3
Cont..4Fig 1. Terms of SQL & MongoDB Key points of MongoDB1. Develop Faster2. Deploy Easier3. Scale Bigger In MongoDB , Fields contains set of key & value pair.
Why use MongoDB ? MongoDB stores documents (or) objects. Now-a-days, everyone works with objects (Python/Ruby/Java/etc.). And we need Databases to persist our objects. Then why not store objects directly ? Embedded documents and arrays reduce need for joins. No Joins and No-multi documenttransactions.5What is MongoDB great for? RDBMS replacement for Web Applications. Semi-structured Content Management. Real-time Analytics & High-Speed Logging. Caching and High ScalabilityWeb 2.0, Media, SAAS, Gaming, HealthCare, Finance, Telecom, Government
MongoDB : CAP Approach Focus on Consistency and Partitiontolerance. Consistency all replicas contain the same version of the data. Availability system remains operationalon failing nodes. Partition Tolerance multiple entry points system remains operationalon system split6CA PCAP Theorem: satisfying all three at the same timeis impossible.
Steps for MongoDB Installation7Link For MongoDB : https://www.mongodb.com/download-center/enterprise
8Cont..
9Cont..
10Cont..
11Cont..
12Cont..
13Cont..
14Cont..
15 Suppose in my laptop MongoDB location is as below : Path : C:Program FilesMongoDBServer4.2bin In window, we can write this path as follow :cd C:Program FilesMongoDBServer4.2binand then after write mongo.exe then press enter to start the mongoDB.Cont..Fig. MongoDB Terminal
MongoDB CRUD Operations16Fig. MongoDB Operations
 Create or insert operations add new documents to a collection. If the collection does not currently exist, insert/save operations will create the collection. MongoDB provides the following methods to insert documents into a collection :1) db.collection_name.insertOne() .2) db.collection_name.insertMany() . Other than this two methods one another method also available for creating collections which iswritten below: db.createCollection(“collection_name”) .17Create Operations
db.collection_name.insertOne() This command is use for inserting one document at a time in the collection.18 For Eg. :
db.collection_name.insertMany() This command is use for inserting multiple document at a time in the collection.19 For Eg. :
db.createCollection(“collection_name”) This command is use for creating collection.20 For Eg. :
 Read operations retrieves documents from a collection; i.e. queries a collection for documents. MongoDB provides the following methods to read documents from a collection:1) db.collection_name.find() . If we execute the above query for read or display the collection data then it is not produce outputin human readable form or we can say that it produces output in linear sequence. If we want to display the output in humane readable or well formatted way then write belowcommand: db.collection_name.find().pretty() .21Read Operations
Cont...22 For Eg. :
 Update operations modify existing documents in a collection. MongoDB provides the following methods to update documents of a collection:1) db.collection_name.updateOne() : This command is use for updating or modifying document value or add a new keyattribute into the existing collection at a time only one updated.2) db.collection_name.updateMany() : This command is use for updating or modifying document value or add a new keyattribute into the existing collection at a time multiple updated.3) db.collection_name.replaceOne() : This method actually work by replacing entire existing document with newdocument. It is not use for modifying the existing document. In MongoDB, update operations target a single collection. All write operations in MongoDB areatomic on the level of a single document.23Update Operations
Cont...24 For Eg. :1) db.collection_name.updateOne() :
Cont...25 For Eg. :2) db.collection_name.updateMany() :
Cont...26 For Eg. :3) db.collection_name.replaceOne() :
 Delete operations remove documents from a collection. MongoDB provides the following methods to delete documents of a collection:1) db.collection_name.deleteOne() : This command is use for removing or deleting document from the collection at atime only one deleted.2) db.collection_name.deleteMany() : This command is use for removing or deleting document from the collection at atime many deleted. In MongoDB, delete operations target a single collection. All write operations in MongoDB are atomic on the level of a single document.27Delete Operations
Cont...28 For Eg. :1) db.collection_name.deleteOne() :
Cont...29 For Eg. :2) db.collection_name.deleteMany() :
 The MongoDB shell is an interactive JavaScript shell. As such, it provides the capability to use JavaScript code directly in the shell or executed as astandalone JavaScript file. You can write scripts for the mongo shell in JavaScript that manipulate data in MongoDB orperform administrative operation.30MongoDB through JavaScript Shell
 OPENING NEW CONNECTIONS From the mongo shell or from a JavaScript file, you can instantiate database connectionsusing the Mongo() constructor: new Mongo() new Mongo(<host>) new Mongo(<host: port>) Consider the following example that instantiates a new connection to the MongoDB instancerunning on localhost on the default port and sets the global db variable to myDatabase usingthe getDB() method: conn = new Mongo(); db = conn.getDB("myDatabase");31Cont...
 DIFFERENCE BETWEEN SHELL HELPERS AND JS EQUIVALENTS32Cont...
 db.adminCommand() db.adminCommand() runs commands against the admin database regardless of the databasecontext in which it runs. EXAMPLE: The following example uses db.adminCommand() to execute therenameCollection administrative database command to rename the orders collection in thetest database to orders-2016.db.adminCommand ({renameCollection: "test.orders",to: "test.orders-2016“})33Cont...
34Cont... db.getCollectionName() Returns an array containing the names of all collections and views in the current database, orif running with access control, the names of the collections according to user’s privilege. EXAMPLE: The following returns the names of all collections in the records database:use recordsdb.getCollectionNames() The method returns the names of the collections in an array:[ "employees", "products", "mylogs", "system.indexes" ]
35Cont... db.getUsers() Returns information for all the users in the database. EXAMPLE:To view all users for the current database who have SCRAM-SHA-256 credentials:db.getUsers({ filter: { mechanisms: "SCRAM-SHA-256" } })
36Cont... Scripting From the system prompt, use mongo to evaluate JavaScript.1) --eval option : Use the --eval option to mongo to pass the shell a JavaScript fragment, as in thefollowing: mongo test --eval "printjson(db.getCollectionNames())"2) Execute a JavaScript file : You can specify a .js file to the mongo shell, and mongo will execute the JavaScriptdirectly. Consider the following example: mongo localhost:27017/test myjsfile.js This operation executes the myjsfile.js script in a mongo shell that connects to the testdatabase on the mongod instance accessible via the localhost interface on port 27017.3) Load a JavaScript : This function loads and executes the myjstest.js file. You can execute a .js file from within the mongo shell, using the load() function, as in thefollowing: load("myjstest.js")
References371) https://www.javatpoint.com/mongodb-tutorial2) https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/3) https://docs.mongodb.com/manual/crud/4) https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
38

Recommended

PPTX
Getting Started with MongoDB
PDF
MongoDB - An Introduction
PPT
Mongo db basics
PDF
MongoDB
PPT
MongoDB
PPS
Ado.net session08
PPTX
Data Management 3: Bulletproof Data Management
PDF
NoSQL Best Practices for PostgreSQL / Дмитрий Долгов (Mindojo)
 
PPTX
Tms training
PPTX
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
PPTX
Data Management 2: Conquering Data Proliferation
PDF
Creating, Updating and Deleting Document in MongoDB
PPTX
introduction to Mongodb
 
PDF
An introduction to MongoDB
PPTX
Mongo DB Presentation
ODP
Mongo indexes
PDF
The Ring programming language version 1.6 book - Part 30 of 189
PPT
2011 mongo FR - scaling with mongodb
PDF
New Features in Apache Pinot
PDF
Superficial mongo db
PPTX
introtomongodb
PPTX
Indexing with MongoDB
PPT
5 Pitfalls to Avoid with MongoDB
PPTX
MongoDB
PPT
2011 Mongo FR - MongoDB introduction
PPTX
Introduction to NOSQL And MongoDB
PDF
Los Angeles R users group - Dec 14 2010 - Part 2
PDF
Indexing and Query Optimizer (Mongo Austin)
PPTX
Mongo db
PPTX
No SQL DB lecture showing structure and syntax

More Related Content

PPTX
Getting Started with MongoDB
PDF
MongoDB - An Introduction
PPT
Mongo db basics
PDF
MongoDB
PPT
MongoDB
PPS
Ado.net session08
PPTX
Data Management 3: Bulletproof Data Management
PDF
NoSQL Best Practices for PostgreSQL / Дмитрий Долгов (Mindojo)
 
Getting Started with MongoDB
MongoDB - An Introduction
Mongo db basics
MongoDB
MongoDB
Ado.net session08
Data Management 3: Bulletproof Data Management
NoSQL Best Practices for PostgreSQL / Дмитрий Долгов (Mindojo)
 

What's hot

PPTX
Tms training
PPTX
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
PPTX
Data Management 2: Conquering Data Proliferation
PDF
Creating, Updating and Deleting Document in MongoDB
PPTX
introduction to Mongodb
 
PDF
An introduction to MongoDB
PPTX
Mongo DB Presentation
ODP
Mongo indexes
PDF
The Ring programming language version 1.6 book - Part 30 of 189
PPT
2011 mongo FR - scaling with mongodb
PDF
New Features in Apache Pinot
PDF
Superficial mongo db
PPTX
introtomongodb
PPTX
Indexing with MongoDB
PPT
5 Pitfalls to Avoid with MongoDB
PPTX
MongoDB
PPT
2011 Mongo FR - MongoDB introduction
PPTX
Introduction to NOSQL And MongoDB
PDF
Los Angeles R users group - Dec 14 2010 - Part 2
PDF
Indexing and Query Optimizer (Mongo Austin)
Tms training
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Data Management 2: Conquering Data Proliferation
Creating, Updating and Deleting Document in MongoDB
introduction to Mongodb
 
An introduction to MongoDB
Mongo DB Presentation
Mongo indexes
The Ring programming language version 1.6 book - Part 30 of 189
2011 mongo FR - scaling with mongodb
New Features in Apache Pinot
Superficial mongo db
introtomongodb
Indexing with MongoDB
5 Pitfalls to Avoid with MongoDB
MongoDB
2011 Mongo FR - MongoDB introduction
Introduction to NOSQL And MongoDB
Los Angeles R users group - Dec 14 2010 - Part 2
Indexing and Query Optimizer (Mongo Austin)

Similar to MongoDB installation,CRUD operation & JavaScript shell

PPTX
Mongo db
PPTX
No SQL DB lecture showing structure and syntax
PDF
full stack modul 5, mongodb,webpack,front-end,back-end
PPTX
Introduction To MongoDB
PPTX
MongoDB - An Introduction
PPTX
fard car.pptx
PPTX
MONGODB koko ko kok k ok kk ok okoko.pptx
PPTX
Introduction to MongoDB – A NoSQL Database
PPTX
MongoDB introduction features -presentation - 2.pptx
PPTX
Introduction to MongoDB
PDF
Mongo db
PPTX
MongoDB-presentation.pptx
PPTX
Full Stack Development Unit 3 GTU MCA.pptx
PPTX
mongo.pptx
PPTX
MongoDB_ppt.pptx
PPTX
MongoDB is a document database. It stores data in a type of JSON format calle...
PDF
MongoDB for Coder Training (Coding Serbia 2013)
PPTX
Mongodb hackathon 02
PDF
Quick overview on mongo db
PPTX
Mongo db queries
Mongo db
No SQL DB lecture showing structure and syntax
full stack modul 5, mongodb,webpack,front-end,back-end
Introduction To MongoDB
MongoDB - An Introduction
fard car.pptx
MONGODB koko ko kok k ok kk ok okoko.pptx
Introduction to MongoDB – A NoSQL Database
MongoDB introduction features -presentation - 2.pptx
Introduction to MongoDB
Mongo db
MongoDB-presentation.pptx
Full Stack Development Unit 3 GTU MCA.pptx
mongo.pptx
MongoDB_ppt.pptx
MongoDB is a document database. It stores data in a type of JSON format calle...
MongoDB for Coder Training (Coding Serbia 2013)
Mongodb hackathon 02
Quick overview on mongo db
Mongo db queries

More from ShahDhruv21

PPTX
Semantic net in AI
PPTX
Error Detection & Error Correction Codes
PPTX
Secure Hash Algorithm (SHA)
PPTX
Data Mining in Health Care
PPTX
Data Compression in Data mining and Business Intelligencs
PPTX
2D Transformation
PPTX
Interpreter
PPTX
Topological Sorting
PPTX
Pyramid Vector Quantization
PPTX
Event In JavaScript
PPTX
JSP Directives
PPTX
WaterFall Model & Spiral Mode
Semantic net in AI
Error Detection & Error Correction Codes
Secure Hash Algorithm (SHA)
Data Mining in Health Care
Data Compression in Data mining and Business Intelligencs
2D Transformation
Interpreter
Topological Sorting
Pyramid Vector Quantization
Event In JavaScript
JSP Directives
WaterFall Model & Spiral Mode

Recently uploaded

PDF
AI-Driven CTI for Business: Emerging Threats, Attack Strategies, and Defensiv...
PPTX
Plant Performance Strategies: Enhanced Reliability & Operational Efficiency w...
PPTX
Step-by-step guide to designing standard a microbiology laboratory in pharmac...
PPTX
Data Science with R Final yrUnit II.pptx
PPTX
Takt Time vs Cycle Time vs Lead Time.pptx
PPTX
Cloud vs On-Premises CMMS — Which Maintenance Platform Is Better for Your Plant?
PPT
63490613-Boiler-Tube-Leakage-analysis-symptoms-causes.ppt
PPTX
How to Select the Right CMMS Software for Your Organization — A Complete Buye...
PDF
Handheld_Laser_Welding_Presentation 2.pdf
PDF
Lecture -06-Hybrid Policies - Chapter 7- Weeks 6-7.pdf
PDF
Surveillance_Partner_Product_Training_20240120_KSA.pdf
PPTX
How to Implement Kaizen in Your Organization for Continuous Improvement Success
PPTX
Revolutionizing Facilities Management with MaintWiz — AI CMMS for Smart FMaaS
PPTX
Optimizing Operations: Key Elements of a Successful Plant Maintenance Plan — ...
PPTX
ISO 14224 Compliance & CMMS Software — A Comprehensive Guide for Reliable Mai...
PPTX
TPM Metrics & Measurement: Drive Performance Excellence with TPM | MaintWiz
PDF
Hybrid Anomaly Detection Mechanism for IOT Networks
PDF
Structural Conservation Appraisal of Indian Monuments Preserving India’s Arch...
PPTX
علي نفط.pptx هندسة النفط هندسة النفط والغاز
PPTX
MECCA Empire – Hotel Shuttle System for the 2026 FIFA World Cup
 
AI-Driven CTI for Business: Emerging Threats, Attack Strategies, and Defensiv...
Plant Performance Strategies: Enhanced Reliability & Operational Efficiency w...
Step-by-step guide to designing standard a microbiology laboratory in pharmac...
Data Science with R Final yrUnit II.pptx
Takt Time vs Cycle Time vs Lead Time.pptx
Cloud vs On-Premises CMMS — Which Maintenance Platform Is Better for Your Plant?
63490613-Boiler-Tube-Leakage-analysis-symptoms-causes.ppt
How to Select the Right CMMS Software for Your Organization — A Complete Buye...
Handheld_Laser_Welding_Presentation 2.pdf
Lecture -06-Hybrid Policies - Chapter 7- Weeks 6-7.pdf
Surveillance_Partner_Product_Training_20240120_KSA.pdf
How to Implement Kaizen in Your Organization for Continuous Improvement Success
Revolutionizing Facilities Management with MaintWiz — AI CMMS for Smart FMaaS
Optimizing Operations: Key Elements of a Successful Plant Maintenance Plan — ...
ISO 14224 Compliance & CMMS Software — A Comprehensive Guide for Reliable Mai...
TPM Metrics & Measurement: Drive Performance Excellence with TPM | MaintWiz
Hybrid Anomaly Detection Mechanism for IOT Networks
Structural Conservation Appraisal of Indian Monuments Preserving India’s Arch...
علي نفط.pptx هندسة النفط هندسة النفط والغاز
MECCA Empire – Hotel Shuttle System for the 2026 FIFA World Cup
 

MongoDB installation,CRUD operation & JavaScript shell

  • 1.
    A. D. PatelInstitute Of TechnologyBig Data and Analytics [2171607] : A. Y. 2019-20Installing MongoDB , Querying through MongoDB &MongoDB through JavaScript ShellPrepared By :Dhruv V. Shah (160010116053)B.E. (IT) Sem - VIIGuided By :Dr. Narendra Chauhan(Head Of IT Dept. , ADIT)Department Of Information TechnologyA.D. Patel Institute Of Technology (ADIT)New Vallabh Vidyanagar , Anand , Gujarat1
  • 2.
    Outline Introduction WhyUse MongoDB ? & What is MongoDB great for? MongoDB : CAP Approach. Steps for MongoDB Installation MongoDB CRUD Operations MongoDB through JavaScript Shell References2
  • 3.
    Introduction What isMongoDB ? MongoDB is a general purpose, document-based, distributed database built for modernapplication developers and for the cloud era. MongoDB is a document database, which means it stores data in JSON-like documents (calledBSON [Binary JavaScript Object Notation]). It falls under the category of a NoSQL database. MongoDB is Scalable High-Performance Open-source, Document-orientated database. Built for Speed. Rich Document based queries for Easy readability. Full Index Support for High Performance. Replication and Failover for High Availability. Auto Sharding for Easy Scalability. Map / Reduce for Aggregation.3
  • 4.
    Cont..4Fig 1. Termsof SQL & MongoDB Key points of MongoDB1. Develop Faster2. Deploy Easier3. Scale Bigger In MongoDB , Fields contains set of key & value pair.
  • 5.
    Why use MongoDB? MongoDB stores documents (or) objects. Now-a-days, everyone works with objects (Python/Ruby/Java/etc.). And we need Databases to persist our objects. Then why not store objects directly ? Embedded documents and arrays reduce need for joins. No Joins and No-multi documenttransactions.5What is MongoDB great for? RDBMS replacement for Web Applications. Semi-structured Content Management. Real-time Analytics & High-Speed Logging. Caching and High ScalabilityWeb 2.0, Media, SAAS, Gaming, HealthCare, Finance, Telecom, Government
  • 6.
    MongoDB : CAPApproach Focus on Consistency and Partitiontolerance. Consistency all replicas contain the same version of the data. Availability system remains operationalon failing nodes. Partition Tolerance multiple entry points system remains operationalon system split6CA PCAP Theorem: satisfying all three at the same timeis impossible.
  • 7.
    Steps for MongoDBInstallation7Link For MongoDB : https://www.mongodb.com/download-center/enterprise
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
    15 Suppose inmy laptop MongoDB location is as below : Path : C:Program FilesMongoDBServer4.2bin In window, we can write this path as follow :cd C:Program FilesMongoDBServer4.2binand then after write mongo.exe then press enter to start the mongoDB.Cont..Fig. MongoDB Terminal
  • 16.
  • 17.
     Create orinsert operations add new documents to a collection. If the collection does not currently exist, insert/save operations will create the collection. MongoDB provides the following methods to insert documents into a collection :1) db.collection_name.insertOne() .2) db.collection_name.insertMany() . Other than this two methods one another method also available for creating collections which iswritten below: db.createCollection(“collection_name”) .17Create Operations
  • 18.
    db.collection_name.insertOne() This commandis use for inserting one document at a time in the collection.18 For Eg. :
  • 19.
    db.collection_name.insertMany() This commandis use for inserting multiple document at a time in the collection.19 For Eg. :
  • 20.
    db.createCollection(“collection_name”) This commandis use for creating collection.20 For Eg. :
  • 21.
     Read operationsretrieves documents from a collection; i.e. queries a collection for documents. MongoDB provides the following methods to read documents from a collection:1) db.collection_name.find() . If we execute the above query for read or display the collection data then it is not produce outputin human readable form or we can say that it produces output in linear sequence. If we want to display the output in humane readable or well formatted way then write belowcommand: db.collection_name.find().pretty() .21Read Operations
  • 22.
  • 23.
     Update operationsmodify existing documents in a collection. MongoDB provides the following methods to update documents of a collection:1) db.collection_name.updateOne() : This command is use for updating or modifying document value or add a new keyattribute into the existing collection at a time only one updated.2) db.collection_name.updateMany() : This command is use for updating or modifying document value or add a new keyattribute into the existing collection at a time multiple updated.3) db.collection_name.replaceOne() : This method actually work by replacing entire existing document with newdocument. It is not use for modifying the existing document. In MongoDB, update operations target a single collection. All write operations in MongoDB areatomic on the level of a single document.23Update Operations
  • 24.
    Cont...24 For Eg.:1) db.collection_name.updateOne() :
  • 25.
    Cont...25 For Eg.:2) db.collection_name.updateMany() :
  • 26.
    Cont...26 For Eg.:3) db.collection_name.replaceOne() :
  • 27.
     Delete operationsremove documents from a collection. MongoDB provides the following methods to delete documents of a collection:1) db.collection_name.deleteOne() : This command is use for removing or deleting document from the collection at atime only one deleted.2) db.collection_name.deleteMany() : This command is use for removing or deleting document from the collection at atime many deleted. In MongoDB, delete operations target a single collection. All write operations in MongoDB are atomic on the level of a single document.27Delete Operations
  • 28.
    Cont...28 For Eg.:1) db.collection_name.deleteOne() :
  • 29.
    Cont...29 For Eg.:2) db.collection_name.deleteMany() :
  • 30.
     The MongoDBshell is an interactive JavaScript shell. As such, it provides the capability to use JavaScript code directly in the shell or executed as astandalone JavaScript file. You can write scripts for the mongo shell in JavaScript that manipulate data in MongoDB orperform administrative operation.30MongoDB through JavaScript Shell
  • 31.
     OPENING NEWCONNECTIONS From the mongo shell or from a JavaScript file, you can instantiate database connectionsusing the Mongo() constructor: new Mongo() new Mongo(<host>) new Mongo(<host: port>) Consider the following example that instantiates a new connection to the MongoDB instancerunning on localhost on the default port and sets the global db variable to myDatabase usingthe getDB() method: conn = new Mongo(); db = conn.getDB("myDatabase");31Cont...
  • 32.
     DIFFERENCE BETWEENSHELL HELPERS AND JS EQUIVALENTS32Cont...
  • 33.
     db.adminCommand() db.adminCommand()runs commands against the admin database regardless of the databasecontext in which it runs. EXAMPLE: The following example uses db.adminCommand() to execute therenameCollection administrative database command to rename the orders collection in thetest database to orders-2016.db.adminCommand ({renameCollection: "test.orders",to: "test.orders-2016“})33Cont...
  • 34.
    34Cont... db.getCollectionName() Returnsan array containing the names of all collections and views in the current database, orif running with access control, the names of the collections according to user’s privilege. EXAMPLE: The following returns the names of all collections in the records database:use recordsdb.getCollectionNames() The method returns the names of the collections in an array:[ "employees", "products", "mylogs", "system.indexes" ]
  • 35.
    35Cont... db.getUsers() Returnsinformation for all the users in the database. EXAMPLE:To view all users for the current database who have SCRAM-SHA-256 credentials:db.getUsers({ filter: { mechanisms: "SCRAM-SHA-256" } })
  • 36.
    36Cont... Scripting Fromthe system prompt, use mongo to evaluate JavaScript.1) --eval option : Use the --eval option to mongo to pass the shell a JavaScript fragment, as in thefollowing: mongo test --eval "printjson(db.getCollectionNames())"2) Execute a JavaScript file : You can specify a .js file to the mongo shell, and mongo will execute the JavaScriptdirectly. Consider the following example: mongo localhost:27017/test myjsfile.js This operation executes the myjsfile.js script in a mongo shell that connects to the testdatabase on the mongod instance accessible via the localhost interface on port 27017.3) Load a JavaScript : This function loads and executes the myjstest.js file. You can execute a .js file from within the mongo shell, using the load() function, as in thefollowing: load("myjstest.js")
  • 37.
    References371) https://www.javatpoint.com/mongodb-tutorial2) https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/3)https://docs.mongodb.com/manual/crud/4) https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
  • 38.

[8]ページ先頭

©2009-2025 Movatter.jp