= new Mongo ("localhost");Get database serviceMongo m = new Mongo ("localhost", 27017);Get Database MyTestDB db = M.getdb ("mytest");Get all the table names under the MyTest databaseSetfor (String s:colls) {System.out.println (s);}Get testcollection TableDbcollection coll = db.getcollection ("testcollection");New A Basicdbobject object docBasicdbobject doc = new Basicdbobject ();Assign valueDoc.put ("name", "MongoDB");Doc.put ("type", "database");Doc
the last operation
Db.getpreverror ()
Return error of previous operation
Db.reseterror ()
Clear Error logging
Manage commands
Db.clonedatabase (Fromhost)
Copies the current data database from another specified host. The fromhost must be in Noauth mode.
Db.copydatabase (Fromdb, Todb, Fromhost)
Copy the Fromhost Fromdb database to the TODB database of the curren
Frequently used commands and their introduction to advanced command usageOne: Add or delete to change the advanced application of the detailed description: * * * * * * * * When C1 is not in the words will be automatically created * * * Regardless of the insertion of the record will automatically give a value ID self-increment primary key unique insert and save (when the ID conflict is modified, otherwise inserted) one: ID primary key does not conflic
Each mongodb server supports multiple databases. For security and convenience management, each database is independent, and the data of each database is also stored separately.
A database consists of one or more sets, and documents (objects) are stored in the collection. An optional security certificate can control access.
Command
Introduction
The mongo database has a concept of database commands. Database
connection address of the current db. getMongo (); Help command prompt help db. help (); db. yourColl. help (); db. youColl. find (). help (); rs. help (); clone the database db from the specified host. cloneDatabase ("127.0.0.1 ");?? Clone the database data on the specified machine to the current database and copy the data from the specified machine to a database. copyDatabase ("mydb", "temp", "127.0.0.1 ″);? Copy the mydb data of the local machine to the temp database to repair the current da
copied, so each host needs to be compressed separately.
Currently, compression is the command that is released to mongod. In a partition environment, each partition should be compressed separately as a maintenance operation. (May be changed in future versions, along with other enhancements)
A set of fixed sizes cannot be compressed. (However, documents in a fixed-size set are not managed by fragments .)
Copy Group
Compress each member individually.
The ideal compression is to run on a sec
student table and specify the AGEGT;20> Db.student.find ({age:{$gt: 20}},{name:1,age:1}){"_id": ObjectId ("5740c1419bc83e10802f1cd6"), "name": "Tom", "Age": 23}{"_id": ObjectId ("5740dc369bc83e10802f1cd7"), "name": "Jerry", "Age": 30}{"_id": ObjectId ("5742263773344acd707888ba"), "name": "Gu Zenghui", "Age": 25}13. Sort by ageAscending: Db.student.find (). Sort ({age:1})Descending: Db.student.find (). Sort ({age:-1})14. Query for data with the name Jerry and age 30Db.student.find ({name: "Jerry
collectionA collection is a container in which n multiple data can be placed insideThis data can be filtered, sorteddb.remove a document from the collection parameter 1: Filter criteria. Parameter 2: Optional parameter, whether single row delete, default false. db.Ordb.{upsert:true,multi:true}) update a document in a collectionParameter one: Update the condition of the documentParameter two: Update operators used when updating, and update propertiesCommon operators: $inc recursive the field va
Tags: exsi conversion switch Call and Zha des count () border After the successful start of MongoDB, and then open a command line window input MONGO, you can do some of the database operations. Enter help to see the basic Operations Command: Show DBS: Display Database list Show Collections: Displays a collection in the current database (similar to a table in a relational database) Show Users: Show user Use MongoD
Label:Learn a little bit every day, progress a little, record a little, share a little, summarize a little. First, the basic application 1. Common commands Show DBS Display Database list Use dbname into the dbname database, case sensitive, no this database does not matter Show Collections displays a collection in the database, equivalent to a table 2. Create and add Db.users.save ({"Name": "LECAF"}) created a collection named users and added a new {"N
Label:MongoDB Common commands: Talk about a special situation, if the admin uses encryption, then you create a database must be encrypted to use, this is the problem I personally met. Enter the MongoDB command line, note: The default entry is the test library $mongo//admin is the core group of database management, the total permissions console, stored the user name password role and other information. Cre
TableName where key01=valu01 and key02=valu02Not equal to Operation: Db.collections.find ({key01:{$ne: valu01}}); SELECT * from TableName where key01 $not Related actions: Db.collections.find ({key:{$not: {$in: [valu01,valu02]}}}); SELECT * from TableName where key not in (VALU01,VALU02)Note: Db.collections.find (key:{$not: valu01}); No such wording.Regular Expressions: Follow-up studiesRelated Operations for arrays$mod: Modulo function$inc$maxscan: Make the maximum number of scanned documents
Tags: mongodbMONGO official website Http://www.mongodb.org/downloadsVue Tools Download http://www.mongovue.com/downloads/Build a folder, put the extracted MONGO file, in the new one put the specified databaseMake a variable, specify binThe following folders and paths can be customizedMongod--dbpath D:\installSoft\mongoDbDATAMONGO 127.0.0.1:27017/adminHere is a simple commandDownload MongoDB specified path datamongod--dbpath e:\
does not replace the original data, so the correct way to update it is as follows:Db.unicorns.update ({name: ' Jingdong '}, {$set: {weight:590}})Db.unicorns.update ({name: ' Pilot '}, {$inc: {If there is an update, add db.hits.update ({page: ' Unicorns '}, {$inc: {hits:1}}, True);d b.hits.find (), or True (upset) using the third parameter setting, default is False#批量更新db. Unicorns.update ({}, {$set: {vaccinated:true}});d B.unicorns.find ({vaccinated:true}); All data will not be vaccinated is up
Db.createcollection ("tablename")//CREATE TABLE
Use Password to access
Use admin
Db.adduser ("admin", "admin")//here must set the password, otherwise the test database settings password is not valid
Db.auth ("admin", "admin")
Use test
Db.adduser ("Test", "test")
============================= Other Commands ================================
Db. AddUser (username,password) Add user
Db.auth (Usrename,password) Set up database connection verif
Label:1. Add the user to the TD database using use TD and then execute Db.adduser ("name", "password"); can be added;2. Enable users to use Db.auth ("name", "password");3. Generally in the project we want to enable security checks, in the configuration of the MongoDB database path at the time after adding--auth so that the security check is started, not the database user is not able to operate the database;4. Delete a user using Db.system.users.remove
Label:The MongoDB shell is more than just an interactive shell, it also supports execution of specified JavaScript files, and also supports execution of specified command fragments. With this feature, MongoDB can be combined with the Linux shell to do most of the daily management and maintenance work.executes the specified commandFor example, there are several common ways to query the number of records in t
}). ForEach (Printjson);Db.users.find ({age: {$lte: +}}, {age:true}). ForEach (Printjson);Exclude The Age columnDb.users.find ({age: {$lte: +}}, {Age:false}). ForEach (Printjson); 9. The Foreach transfer function displays informationDb.things.find ({x:4}). ForEach (function (x) {print (Tojson (x));}); Some of the commands that you might use: $ne: Not equal to$GT: Greater Than$LT: Less than$gte: greater than or equal to$lte: Less than or equal to Curr
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.