Monday, 25 June 2018

MongoDB tutorial

https://www.youtube.com/playlist?list=PL6gx4Cwl9DGDQ5DrbIl20Zu9hx1IjeVhO

command

switch to/ create db

use xxx

drop database

db.dropDatabase()

insert

db.collectionName.insert(json)
db.collectionName.insert([jsons])

show collections

show collections

search

db.collectionName.find(json criteria)
db.collectionName.findOne()
db.collectionName.find(
    json criteria,
    {"name":1, _id:0}           display name, not _id
)
db.collectionName.find().limit(3)
db.collectionName.find().skip(2)

delete

db.collectionName.remove(json criteria)

update

db.collectionName.update(json criteria, json obj)

json criteria

{"position":"defenders", "age":21}

{
   $or:[
           {"position": "left wing"},
           {"position": "right wing"}
     ]
}

{"age": {$gt:30}}   gt>   lt<   gte>=    lte<=  ne!=

index

db.collectionName.find(json critera),explain("executionStats")
db.collectionName.ensureIndex({"age":1})
db.collectionName.getIndexes()
db.collectionName.droptIndex({"age":1})

aggregation and groups

db.collectionName.aggregate({
    $group:{
          _id: "$groupColumn",
          total: {$sum: 1},
          avg: {$avg: "avgColumn"},
          max: {$max: "maxColumn"
      }
})



json generator
https://next.json-generator.com/

mongoDB community
https://www.mongodb.com/download-center?jmp=nav#community

mongoDB compass
https://www.mongodb.com/download-center#compass

Studio 3T
https://studio3t.com/download-thank-you/?OS=win64

No comments:

Post a Comment