MongoDB Exercise :2

 studentsB> db.aids.find().count()

4

studentsB> db.aids.find().count()

4

studentsB> db.aids.find().limit(3)

[

  {

    _id: ObjectId("66fa2428ca0fc631a23b264f"),

    SRN: 201,

    SName: 'A',

    yr: 3

  },

  {

    _id: ObjectId("66fa2479ca0fc631a23b2650"),

    SRN: 202,

    SName: 'B',

    yr: 3

  },

  {

    _id: ObjectId("66fa249eca0fc631a23b2652"),

    SRN: 303,

    SName: 'CC',

    yr: 3

  }

]

studentsB> db.aids.find().limit(2)

[

  {

    _id: ObjectId("66fa2428ca0fc631a23b264f"),

    SRN: 201,

    SName: 'A',

    yr: 3

  },

  {

    _id: ObjectId("66fa2479ca0fc631a23b2650"),

    SRN: 202,

    SName: 'B',

    yr: 3

  }

]

studentsB> db.aids.find().sort()

[

  {

    _id: ObjectId("66fa2428ca0fc631a23b264f"),

    SRN: 201,

    SName: 'A',

    yr: 3

  },

  {

    _id: ObjectId("66fa2479ca0fc631a23b2650"),

    SRN: 202,

    SName: 'B',

    yr: 3

  },

  {

    _id: ObjectId("66fa249eca0fc631a23b2652"),

    SRN: 303,

    SName: 'CC',

    yr: 3

  },

  {

    _id: ObjectId("66fa361cefea40aa66eff667"),

    SRN: 304,

    SName: 'DD',

    yr: 2

  },

  {

    _id: ObjectId("66fa3631efea40aa66eff668"),

    SRN: 305,

    SName: 'EE',

    yr: 2

  }

]

studentsB> db.aids.find().sort({SRN:1})

[

  {

    _id: ObjectId("66fa2428ca0fc631a23b264f"),

    SRN: 201,

    SName: 'A',

    yr: 3

  },

  {

    _id: ObjectId("66fa2479ca0fc631a23b2650"),

    SRN: 202,

    SName: 'B',

    yr: 3

  },

  {

    _id: ObjectId("66fa249eca0fc631a23b2652"),

    SRN: 303,

    SName: 'CC',

    yr: 3

  },

  {

    _id: ObjectId("66fa361cefea40aa66eff667"),

    SRN: 304,

    SName: 'DD',

    yr: 2

  },

  {

    _id: ObjectId("66fa3631efea40aa66eff668"),

    SRN: 305,

    SName: 'EE',

    yr: 2

  }

]

studentsB> db.aids.find().sort({SRN:-1})

[

  {

    _id: ObjectId("66fa3631efea40aa66eff668"),

    SRN: 305,

    SName: 'EE',

    yr: 2

  },

  {

    _id: ObjectId("66fa361cefea40aa66eff667"),

    SRN: 304,

    SName: 'DD',

    yr: 2

  },

  {

    _id: ObjectId("66fa249eca0fc631a23b2652"),

    SRN: 303,

    SName: 'CC',

    yr: 3

  },

  {

    _id: ObjectId("66fa2479ca0fc631a23b2650"),

    SRN: 202,

    SName: 'B',

    yr: 3

  },

  {

    _id: ObjectId("66fa2428ca0fc631a23b264f"),

    SRN: 201,

    SName: 'A',

    yr: 3

  }

]

studentsB> use db123

switched to db db123

db123> db.col1.insert({SNo:1,Name:'aa')}

Uncaught:

SyntaxError: Unexpected token, expected "," (1:31)


> 1 | db.col1.insert({SNo:1,Name:'aa')}

    |                                ^

  2 |


db123> db.col1.insert({SNo:1,Name:'aa'})

DeprecationWarning: Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.

{

  acknowledged: true,

  insertedIds: { '0': ObjectId("66fa37b8efea40aa66eff669") }

}

db123> db.col2.insert({SNo:1,Name:'bb'})

{

  acknowledged: true,

  insertedIds: { '0': ObjectId("66fa37caefea40aa66eff66a") }

}

db123> show collections

col1

col2

db123> db.col1.drop()

true

db123> show collections

col2

db123> db.dropDatabase()

{ ok: 1, dropped: 'db123' }

db123> show dbs

123               40.00 KiB

4B_AIDS           72.00 KiB

OneBBank          72.00 KiB

abc123            72.00 KiB

admin             40.00 KiB

banks             40.00 KiB

config           108.00 KiB

countries         40.00 KiB

csbs             128.00 KiB

db                40.00 KiB

db1               72.00 KiB

db3               72.00 KiB

db5               56.00 KiB

empAV             72.00 KiB

employeeAV        72.00 KiB

employeeHarshil   72.00 KiB

employees        136.00 KiB

local            112.00 KiB

my_db             80.00 KiB

my_dbpy           72.00 KiB

saibaba           72.00 KiB

sports            72.00 KiB

student           48.00 KiB

studentDB         72.00 KiB

studentsB         72.00 KiB

studentsB> db.aids.find()

[witched to db studentsB

  {

    _id: ObjectId("66fa2428ca0fc631a23b264f"),

    SRN: 201,

    SName: 'A',

    yr: 3

  },

  {

    _id: ObjectId("66fa2479ca0fc631a23b2650"),

    SRN: 202,

    SName: 'B',

    yr: 3

  },

  {

    _id: ObjectId("66fa249eca0fc631a23b2652"),

    SRN: 303,

    SName: 'CC',

    yr: 3

  },

  {

    _id: ObjectId("66fa361cefea40aa66eff667"),

    SRN: 304,

    SName: 'DD',

    yr: 2

  },

  {

    _id: ObjectId("66fa3631efea40aa66eff668"),

    SRN: 305,

    SName: 'EE',

    yr: 2

  }

]

studentsB> db.aids.createIndex({SRN:1})

SRN_1

studentsB> db.aids.createIndex({SRN:-1})

SRN_-1

studentsB> db.aids.dropIndex({SRN:-1})

{ nIndexesWas: 3, ok: 1 }

studentsB>


Comments

Popular posts from this blog

9. Angular and MongoDBs

1. a. Angular Application Setup

2. Structural Directives - ngIf