• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to Create,Show,Rename and Drop A Collection In MongoDB 4.0.11 on CentOS 7.6

  • 01:01 mongod --version
  • 01:08 mongo
  • 01:22 show dbs;
  • 01:29 use test;
  • 01:51 db.users.insert( { "id" : 1 } );
  • 02:05 show collections;
  • 02:37 db.createCollection("Linuxhelp")
  • 03:22 db.users.renameCollection("Linux");
  • 03:58 db.Linuxhelp.drop();
  • 04:06 show collections;
{{postValue.id}}

Create,Show,Drop and Rename the Collection In MongoDB 4.0.11 On CentOs 7.6

Syntax :

db.createCollection(name)
show collections;
db.collectionname.renameCollection("New-Collection-Name")
db.collection_name.drop()

Process :

Check the version of MongoDB as follows

[root@linuxhelp ~]# mongod --version
db version v4.0.11
git version: 417d1a712e9f040d54beca8e4943edce218e9a8c
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

Login to the Mongo Shell using the below command

[root@linuxhelp ~]# mongo
MongoDB shell version v4.0.11
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("e13b3eec-2e21-4c0a-a4c2-0571a32d1b3e") }
MongoDB server version: 4.0.11
Server has startup warnings: 
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] 
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] 
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] 
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] 
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-08-06T15:33:04.607+0530 I CONTROL  [initandlisten] 

Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()


####   List the databases present by default in mongoDB
> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB


###  Create a Database named test as follows
> use test;
switched to db test


###   Insert an Users  Document whose id is 1 as follows

> db.users.insert( { "id" : 1 } );
WriteResult({ "nInserted" : 1 })

###    List the collections available in the current database as follows
> show collections;
users

####   List the databases available in the MongoDB
> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB
test    0.000GB

#####  Create a Collection Using the following Syntax
> db.createCollection("Linuxhelp")
{ "ok" : 1 }

#####      List the collection in the current databse using the following syntax
> show collections;
Linuxhelp
users

######    Rename the Collection “Users” as follows

> db.users.renameCollection("Linux");
{ "ok" : 1 }


#######    List the collections in the current database test as follows to verify the renamed Collection.
> show collections;
Linux
Linuxhelp

#####  Drop the Collection as follows
> db.Linuxhelp.drop();
true

######  List the collections in the test database to verify whether the collection has been dropped or not.
> show collections;
Linux

With this.the method to create ,show,rename and drop a collection in MongoDB 4.0.11 On CentOS 7.6 comes to end

Tags:
michael
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What does Collection store In MongoDB?

A

In MongoDB , Collection Stores documents

Q

What is the Document Format that MongoDB stores in Collection?

A

The Document format that MongoDB stores In Collection Is BSON.

Q

What does MongoDB databases hold?

A

In MongoDB,databases holds collections of documents.

Q

Does MongoDB have access control enabled by default?

A

No ,MongoDB has no access control enabled by default.

Q

What is the default port of MongoDB?

A

The default port of MongoDB is 27017

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help David Lopez Guillen ?
Ayuda urgente instale SSL para servidor Opensuse y ahora no funciona tengo servicio web

hola segui este tutorial para tener un certificado ssl y ahora no se ve mi app en la red, espero alguien pueda ayudarme, tengo M9oodle en3.5 en un servidor open suse y ahora no funciona por favor ayuda.

https://www.linuxhelp.com/how-to-create-ssl-certificate-in-opensuse

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.