Category: mongodb

  • Khóa học miễn phí MongoDB – Data Types nhận dự án làm có lương

    MongoDB – Datatypes



    MongoDB supports many datatypes. Some of them are −

    • String − This is the most commonly used datatype to store the data. String in MongoDB must be UTF-8 valid.

    • Integer − This type is used to store a numerical value. Integer can be 32 bit or 64 bit depending upon your server.

    • Boolean − This type is used to store a boolean (true/ false) value.

    • Double − This type is used to store floating point values.

    • Min/ Max keys − This type is used to compare a value against the lowest and highest BSON elements.

    • Arrays − This type is used to store arrays or list or multiple values into one key.

    • Timestamp − ctimestamp. This can be handy for recording when a document has been modified or added.

    • Object − This datatype is used for embedded documents.

    • Null − This type is used to store a Null value.

    • Symbol − This datatype is used identically to a string; however, it”s generally reserved for languages that use a specific symbol type.

    • Date − This datatype is used to store the current date or time in UNIX time format. You can specify your own date time by creating object of Date and passing day, month, year into it.

    • Object ID − This datatype is used to store the document’s ID.

    • Binary data − This datatype is used to store binary data.

    • Code − This datatype is used to store JavaScript code into the document.

    • Regular expression − This datatype is used to store regular expression.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí MongoDB – Advantages nhận dự án làm có lương

    MongoDB – Advantages



    Any relational database has a typical schema design that shows number of tables and the relationship between these tables. While in MongoDB, there is no concept of relationship.

    Advantages of MongoDB over RDBMS

    • Schema less − MongoDB is a document database in which one collection holds different documents. Number of fields, content and size of the document can differ from one document to another.

    • Structure of a single object is clear.

    • No complex joins.

    • Deep query-ability. MongoDB supports dynamic queries on documents using a document-based query language that”s nearly as powerful as SQL.

    • Tuning.

    • Ease of scale-out − MongoDB is easy to scale.

    • Conversion/mapping of application objects to database objects not needed.

    • Uses internal memory for storing the (windowed) working set, enabling faster access of data.

    Why Use MongoDB?

    • Document Oriented Storage − Data is stored in the form of JSON style documents.

    • Index on any attribute

    • Replication and high availability

    • Auto-Sharding

    • Rich queries

    • Fast in-place updates

    • Professional support by MongoDB

    Where to Use MongoDB?

    • Big Data

    • Content Management and Delivery

    • Mobile and Social Infrastructure

    • User Data Management

    • Data Hub


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí MongoDB – Drop Database nhận dự án làm có lương

    MongoDB – Drop Database



    In this chapter, we will see how to drop a database using MongoDB command.

    The dropDatabase() Method

    MongoDB db.dropDatabase() command is used to drop a existing database.

    Syntax

    Basic syntax of dropDatabase() command is as follows −

    db.dropDatabase()
    

    This will delete the selected database. If you have not selected any database, then it will delete default ”test” database.

    Example

    First, check the list of available databases by using the command, show dbs.

    >show dbs
    local      0.78125GB
    mydb       0.23012GB
    test       0.23012GB
    >
    

    If you want to delete new database <mydb>, then dropDatabase() command would be as follows −

    >use mydb
    switched to db mydb
    >db.dropDatabase()
    >{ "dropped" : "mydb", "ok" : 1 }
    >
    

    Now check list of databases.

    >show dbs
    local      0.78125GB
    test       0.23012GB
    >
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí MongoDB – Create Collection nhận dự án làm có lương

    MongoDB – Create Collection



    In this chapter, we will see how to create a collection using MongoDB.

    The createCollection() Method

    MongoDB db.createCollection(name, options) is used to create collection.

    Syntax

    Basic syntax of createCollection() command is as follows −

    db.createCollection(name, options)
    

    In the command, name is name of collection to be created. Options is a document and is used to specify configuration of collection.

    Parameter Type Description
    Name String Name of the collection to be created
    Options Document (Optional) Specify options about memory size and indexing

    Options parameter is optional, so you need to specify only the name of the collection. Following is the list of options you can use −

    Field Type Description
    capped Boolean (Optional) If true, enables a capped collection. Capped collection is a fixed size collection that automatically overwrites its oldest entries when it reaches its maximum size. If you specify true, you need to specify size parameter also.
    autoIndexId Boolean (Optional) If true, automatically create index on _id field.s Default value is false.
    size number (Optional) Specifies a maximum size in bytes for a capped collection. If capped is true, then you need to specify this field also.
    max number (Optional) Specifies the maximum number of documents allowed in the capped collection.

    While inserting the document, MongoDB first checks size field of capped collection, then it checks max field.

    Examples

    Basic syntax of createCollection() method without options is as follows −

    >use test
    switched to db test
    >db.createCollection("mycollection")
    { "ok" : 1 }
    >
    

    You can check the created collection by using the command show collections.

    >show collections
    mycollection
    system.indexes
    

    The following example shows the syntax of createCollection() method with few important options −

    > db.createCollection("mycol", { capped : true, autoIndexID : true, size : 6142800, max : 10000 } ){
    "ok" : 0,
    "errmsg" : "BSON field ''create.autoIndexID'' is an unknown field.",
    "code" : 40415,
    "codeName" : "Location40415"
    }
    >
    

    In MongoDB, you don”t need to create collection. MongoDB creates collection automatically, when you insert some document.

    >db.tutorialspoint.insert({"name" : "tutorialspoint"}),
    WriteResult({ "nInserted" : 1 })
    >show collections
    mycol
    mycollection
    system.indexes
    tutorialspoint
    >
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc