Inserting Data :
- Insert One data → db.collectionName.insertOne({ key : value })
- Insert Many Data → db.collectionName.insertMany( [ {} , {} ] )
- Ordered , unordered insert → db.collectionName.insertMany([ {} , {} ] , { ordered : true })
Update Data :
- Update One data → db.collectionName.updateOne( {identifier} , { $set : { data } } )
- Update Many data → db.collectionName.updateMany( {identifier} , { $set : { data } } )
- Increment value → db.collectionName.updateMany( {identifier} , { $inc : { data } } )
- Min Value → db.collectionName.updateMany( {identifier} , { $min : { data } } )
- Max Value → db.collectionName.updateMany( {identifier} , { $max : { data } } )
- Multiply Value → db.collectionName.updateMany( {identifier} , { $mul : { data } } )
- Remove Field → db.collectionName.updateMany( {identifier} , { $unset : { keyName : “” } } )
- Rename Field → db.collectionName.updateMany( {identifier} , { $rename : { data } } )
- Create new doc if it is not exist → db.cn.updateOne({identifier} , { $set : {data} }, { upsert: true } )
- Push a data in array → db.cn.updateOne( {identifier} , { $push : { key : value } } )
- Push many data in array → db.cn.updateOne( {identifier} , { $push : { $each : { key : [ value ] } } } )
- Pop a data in array → db.cn.updateOne( {identifier} , { $pop : { key : 1 or -1 } } )
- Pull a data from array → db.cn.updateOne( {identifier} , { $pull : { key : “value” } } )