collection -> table
use db mydb ->create database if not exist and switch to database
show dbs -> list database
create user
db.createuser({
user:"a",
pwd:"",
roles:["read",write]
})
collections
create collection
db.createCollection('cusomer');
insert data into collection
db.customer.insert({ojectof data});
see data customer collection
db.customer.find([{insert multipale data at a time }]);
create index for each record
update collection filed data
db.cllectionname.update({filename with value to update},{new object which replace existing})
it will update hole object
user $set key word with filed to just update the required filed.
db.collection.update({username:"pawn"},{$set:{gender:"male"});
increment the age with five use $inc:{age:5}
unset->remove an attributes from collection object
$unset:{age:50}
if not found then insert user third param {upset:true}
rename
db.collectionname.update({},{$rename:{"gender":"sex"}})
db.collectionname.remove({name:"Pawan"}) ;
delete one
db.collectionname.remove({name:"Pawan"},{justOne:"true"}) ;
db.collectionname.find($or[{name:"Pawan"},{name:"Sumit"}]) ;
No comments:
Post a Comment