This is a creation in Article, where the information may have evolved or changed.
24. Toad Notes Go language--mongdb database use
MONGDB Database
A Distributed File storage database, an open source project written by the C + + language.
In a NoSQL, the most feature-rich, relational database-like product.
The data structure it supports is very loose and is a JSON-like Bson format, so you can store more complex data models.
Its supported query language is very powerful, its syntax is somewhat similar to object-oriented query language, but also supports the functions of index, MapReduce and so on.
Download installation
Download Address: https://www.mongodb.com/download-center#community
File name:
Mongodb-win32-x86_64-2008plus-ssl-3.2.7-signed.msi
Double-click to install.
After the installation is complete, the path
C:\Program Files\mongodb\server\3.2\bin
All binary files exist.
Add the path to the environment variable path.
Start the database
Run cmd as Administrator.
Then execute:
Mongod--dbpath D:\mongodb\data--logpath=d:\mongodb\logs\mongodb.log--install
Then start MongoDB
Perform:
net start MongoDB
Basic operations
Link Database
Execute MONGO directly.
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
Switch/CREATE Database
Use Yourdb; The current database is created automatically when a collection (table) is created
Delete the currently used database
Db.dropdatabase ();
Repairing the current database
Db.repairdatabase ();
View the database currently in use
Db.getname ();
db The DB and GetName methods are the same effect and can query the currently used database
Show Current DB status
Db.stats ();
Current DB version
Db.version ();
Create a data table
Db.createcollection ("account")
Add user
Old version:
Db.adduser ({User: "Test1",
PWD: "Admin",
roles: ["ReadWrite", "DbAdmin"]
} )
New version:
Db.createuser (
{
User: "Astaxie",
PWD: "Astaxie",
Roles
[
{role: "ReadWrite", DB: "Test"},
]
}
)
Close the database
net stop MongoDB