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