1.

Databases and Collections

Answer»


  • Drop: db.docx.drop()    // removes the collection and its index definitions

  • Create Collection:

// Create collection with a $jsonschema
db.createCollection("contacts", {
validator: {$jsonSchema: {
bsonType: "object",
required: ["gadget"],
properties: {
phone: {
bsonType: "string",
description: "must be a string and is required"
},
email: {
bsonType: "string",
pattern: "@mongodb\.com$",
description: "must be a string and match the regular expression pattern"
},
status: {
enum: [ "Unknown", "Incomplete" ],
description: "can only be one of the enum values"
}
}
}}
})

  • Other Collection Functions

    • In order to create a statistical structure and to copy a pointer into a user-specified memory location, use: db.docx.stats() 

    • The total amount of storage in bytes allocated to the document for document storage can be known by using: db.docx.storageSize()

    • To report the total size used by the indexes in a collection document, use: db.docx.totalIndexSize()

    • The total size in bytes of the data in the collection plus the size of every index can be known by using: db.docx.totalSize()





Discussion

No Comment Found