Mongodb startup and basic commands, mongodb startup commands
1. Start mongodb with Parameters
./Mongod -- dbpath =/usr/local/mongo/mongodb/data -- fork -- logpath =/usr/local/mongo/mongodb/logs -- nohttpinterface
2../mongo connect to mongodb
3. Use ruby to connect to the MongoDB Database
Install ruby and rubygems
Configure the connect. rb File
Run ruby connect. rb to run the connection.
4. Commands
Mongo added
Db. users. insert ({name: "Jony "})
Modify common mongo
Db. users. update ({name: "Jony"}, {$ set: {country: "Fujian "}})
If there is no conutry field in the users set, it is equivalent to adding the country field. If so, modify
Db. users. update ({name: "Jony"}, {country: "Fujian "})
If no $ set exists, the name field is directly deleted and replaced with the country field.
Common mongo Lookup
Db. users. find () or db. users. find ({name: "Jony" },{ country: "Fujian "})
It command
Display the next group of information
Create a large collection
For (I = 0; I <20000; I ++ ){
Db. numbers. save ({num: I });
}
Create an index
Db. numbers. createIndex ({num: 1 })
View Indexes
Db. numbers. getIndexes ()
Display database information
Show dbs
Show all set information
Show collections
View Collection status
Db. stats () or db. numbers. stats ()
Ruby connection Mongo command
Query a set
$ Users. find (). each do | user | put user end
The preceding statement indicates that
Iterate the data in the users set into the user and output the data.
Modify
$ Users. find ({"name" => "Jony"}). update_one ({"$ set" =>{ "city" => "Fuzhou "}})
Delete
$ Users. find ({"name" => "Jony"}). delete_one deletes the first matched
$ Users. find ({"name" => "Jony"}). delete_many delete all matched
Users. drop Delete All sets