Win+r into the DOS command window, enter cmd, enter the directory of the MongoDB EXE file, such as my E:\MongoDB\bin, respectively, execute: "E:" carriage return, then: "CD Mongodb/bin" enter
Enter "MONGO" and start working on the database, I use the 2.6.7 version here.
Description: The command is case-sensitive
Action Commands
Show DBS shows existing Databases
Use database name like MSSQL, using this database
Show collections shows all aggregation collections (equivalent to tables in relational databases)
db.dropdatabase () Delete the currently used database
db View the currently used database name (or:db.getname ())
db.stats () View some information about the current database
db.repairdatabase () Repair Database
Version () View MongoDB versions
Db.getmongo () View current DB connection address
db.getpreverror () error message before query
db.reseterror () Clear error message
Database user
Db.createuser ( { User:"root", pwd:"Root ", roles: [ { role:"useradminanydatabase " , DB:"admin" } ] })
The above code, representing the creation of the user, before executing the use of the database you are using, created by the user only belong to this database, not global users , not to cut into other databases, and then show users under
Roles is a role type, you can show roles to see all the roles, DB is not clear about what, did not find the relevant documents, the default is the current database name bar
Db.adduser () not recommended for use
Db.changeuserpassword ("root", "123456") to modify the user password, the first parameter is the user name to be modified, the second is the new password
db.dropuser ("sa") deletes a user under the current database
db.dropallusers () Delete all users under the current database
db.getuser ("test") gets information about the next user of the current database
db.getusers () gets all users under the current database, equivalent:Show Users
operation of the collection
It can also be called a table operation
You do not need to manually create a table, direct db. The collection name. Insert (stored JSON data) is the creation of a collection (where the collection does not exist) and the data
db. Collection name. Drop () Delete collection
db.getcollection ("collection name") gets the information for a collection
db.getcollectionnames () gets all the collections under the current database
db.printcollectionstats () gets the state of all the collections under the current database
crud of Data
Insert: db. Collection name. Insert ({"name": "Test", "Age":), note that only one of the JSON arrays inserted, "{}", of course, can contain sub-data, but only one set of such data, Otherwise the final inserted data, only the first one, if the JSON inserted is: {"name": "Test", "Age": 12},{"Name": "Demo", "Age": 12}, then the final storage only name=test data
Use loops to insert test data: For(i=0;i<100;i++) db. The collection name. Insert ({"Index": I, "remark": "The index here is:" +i}), just like the notation in the program, you can also stitch strings, Dick Fried Day
Function:
db. Collection name. Count () How many data are there in the current collection
Resources:
MongoDB Chinese Document: http://docs.mongoing.com/manual-zh/
MongoDB Official Document: http://docs.mongodb.org/manual/
MongoDB some basic commands