MongoDB Basic command--database table additions and deletions--traverse the records in the action table

Source: Internet
Author: User
Tags mongodb tutorial

Traversing records in the Update data table

/* * * Add order "  item ID and Item quantity" In order form productiondate  case Data    [{"Productionid": 100001, "Count": 10}, {" Productionid ": 100002," Count ": 9}]***/db. Order . Find (). ForEach (    function(item) {        db. order. Update ({_id:item._id},{$set: {"Productionnum":[{"Productionid": Item.productionid, "Count": Item.count}](}},true)    });

Create a database

 Use database_name

Deleting a database

Db.dropdatabase ()

Create a data table

Db.createcollection ("table name");

Delete a data table

Db. Collection_name. Drop ()

To check the currently selected database using command db

> Dbmydb

If you want to check the database list, use the command show DBS.

> Show Dbslocal      0 . 78125GBtest       0. 23012GB

The basic syntax for the Insert () command is as follows:

/** * * syntax *******/>Db. Collection_name.Insert(document)/** * * example *******/>Db.mycol.Insert({_id:objectid (7df78ad8902c), title:'MongoDB Overview', Description:'MongoDB is no SQL database',    by:'Tutorials Yiibai', URL:'http://www.yiibai.com', Tags:[' MongoDB ', ' database ', ' NoSQL '], likes: -})

Delete a table record

>db. Collection_name.remove (Delletion_critteria)

Querying table Records

>db.mycol.find ({})

Update () Use of updated syntax

>db.mycol. Update ({'title':'MongoDB overview'},{$set: {'  title':'New MongoDB Tutorial'}})  >db.mycol.find ()

Click to view detailed links

MongoDB Basic command--database table additions and deletions--traverse the records in the action table

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.