Create a library database similar to database
// use DATABASE_NAME used to create the database.
This command will create a new database, if it does not exist, otherwise it will return the existing database.
use mydb
switched to db mydb
To check the currently selected database using the command db
>db
mydb
If you want to check the list of databases, use the command show dbs
Note that after use mydb, mydb actually not really set up, but the show is currently in use mkyongdb up.
View course library table below
You can show collections
3) Save the data collection simply use the time to write on will be automatically created or (db.createCollection ( 'users'))
Define a Collection, called "users", then insert the data, as follows:
> db.users.save( {username:"mkyong"} )
> db.users.find()
{ "_id" : ObjectId("4dbac7bfea37068bd0987573"), "username" : "mkyong" }
>
// insert multiple pieces of data
// person just use the time to write on the table is automatically created as a collection of similar database you want to create
db.person.insert
([{name:'Mary',age:21,status:'A'},
{name:'Lucy',age:89,status:'A'},
{name:Jacky,age:30,status:'A'}])
Sphinx full-text search
Role: instead of like fuzzy query, realizes search feature article
Sphinx knowledge
1. Download Resource Kit
2, Sphinx directory
3, modify the configuration file
4, service operations
5, php manipulation Sphinx
NoSQL:Not Only SQL
Features Introduction
MySQL: data volume, low high security, efficiency, speed slow
NoSQL: a small amount of data, security, low, high efficiency and speed
Where is the data stored in
MySQL: more stable data
NoSQL: frequently changing data
NoSQL products
1, Memcache cache
2, MongoDB serves as a small database
3, Redis common variables
MongoDB use
1. Download Resource Kit
mongodb-win32-i386_32-2.6.6.zip(32位)
mongodb-win32-x86_64-2.6.6.zip(64位)
2, in MongoDB Resource Kit New Folder
mongodb
bin -------------------- MongoDB command
data ------------------- storing temporary data generated
db ------------------- store data files
log
MongoDB.log -------- MongoDB log file
3, path environment variable configuration system (Right Computer -> Properties - "Advanced System Settings)
Variable name: path
Variable values: asdfajsdfljadsjasdfj; F: \ mongodb \ bin
4, operation service
1) Installation (open a command prompt, type the following command)
mongod --dbpath "e:/mongodb/data/db" --logpath "e:/mongodb/data/log/mongodb.log" --install --serviceName "MongoDB"
2) Uninstall service (open a command prompt, type the following command)
mongod --remove --serviceName "MongoDB"
3) to start the service (open a command prompt, type the following command)
net start MongoDB
4) Stop the service (open a command prompt, type the following command)
net stop MongoDB
5, landing MongoDB (Open a command prompt, type the following command)
mongo host address: 27017 / library name
mongo host address / library name
mongo host address
CMD window using ordinary run directly off mongo command even if the window does not appear the problem,
It seems closer to the mark using the native program.
It occurred in this case the solution is simple, using the following parameters can repair:
journaling enable error
Copy the code code is as follows:
mongod --auth -dbpath C:\mongo\MongoDB\mongo\data --repair
Port number of 27017 mongo
The way data is stored
MySQL: Library -> Table -> Record -> Fields
MongoDB: Library -> Collections -> Record -> Fields
MongoDB command Note:
1, MongoDB command is case sensitive
2, each command will not write a semicolon
MongoDB operation command
1. Quit
exit
2, clear screen
cls
3, view all existing libraries
show dbs
4, using the library
use the library name
Note: If the library name exists, then switch library. If the library name does not exist, then create a library.
5, delete the database (premise: first into the library to be deleted)
db.dropDatabase()
6, the set of all view the current library
show collections
7, delete the collection
db. collectionname .drop ()
8. Add Record
db collection name .insert. ({name: value name: value name: value ...})
db.userInfo.insert({"userName":"张三","age":30,"sex":"男","address":"北京"})
db.userInfo.insert({"userName":"李四","age":31,"sex":"女","address":"天津"})
db.userInfo.insert({"userName":"王五","age":29,"sex":"女","address":"上海"})
db.userInfo.insert({"userName":"赵六","age":24,"sex":"男","address":"西安"})
db.userInfo.insert({"userName":"田七","age":33,"sex":"女","address":"山西"})
9, modify records
db collection name .update. ({name: value}, {name: value name: value ...})
db.userInfo.update({"userName":"赵六"},{"userName":"赵六","age":24,"sex":"女","address":"西安"})
10, delete records
. Db collection name .remove ({name: value})
db.userInfo.remove({"userName":"赵六"})
db.userInfo.remove({"sex":"男"})
db.userInfo.remove()
11, the query
db collection name .find. ({name: value name: value ...})
db.userInfo.find()
db.userInfo.find({"sex":"女"})
db.userInfo.find().count()
db.userInfo.find().limit(2)
db.userInfo.find().skip(3)
db.userInfo.find().skip(2).limit(3)
db.userInfo.find().limit(3).skip(2)
db.userInfo.findOne({"userName":"田七"})
db.userInfo.findOne({"sex":"男"})
MongoDB PHP manipulation
1, download the php extension MongoDB
First of MongoDB php extensions php_mongo.dll copied to wamp \ bin \ php \ php5.4.16 \ ext in
MongoDB open again in php configuration file php.ini extension = php_mongo.dll extended
2, php actuating codes MongoDB
mongoose create a schema (similar to a database) table format
where