Create/alter/drop table(collection) in MongoDB

Create/alter/drop table(collection) in MongoDB

For Create Table in SQL:

CREATE TABLE employees( id MEDIUMINT NOT NULL  AUTO_INCREMENT,
    emp_id Varchar(30),
    age Number,
    status char(1),
    PRIMARY KEY (id) )
   
For Create table in MongoDB:
—————————-
db.employees.insert( {
    emp_id: “RAM”,
    age: 50,
    status: “A”
 } )

 Or

 db.createCollection(“employees”);

Add column in SQL:
———————
ALTER TABLE employees ADD join_date DATETIME

Add column in collection of MongoDB:
————————————
db.employees.update(
    { },
    { $set: { join_date: “” } },
    { multi: true }
)

Remove column in SQL:
———————-
alter table employees drop column join_date

Remove column in MongoDB:
—————————
db.employees.update(
    { },
    { $unset: { join_date: “” } },
    { multi: true }
)

Drop table SQL:
—————-
drop table users:

Drop collection in Mongdb:
—————————
In MongoDB:
db.users.drop();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.