In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Install MongoDB under Windows:
1. Installation error debugging
98 Unable to create/open lock file: e:\ data\ db\ mongod.lock
Delete mongod.lock (may need to end the process)
2. Create a new log file
Create a new folder log (for log files) and a new file mongodb.log under d:\ data
Create a new file mongo.config in d:\ mongodb
Use notepad to open mongo.config for input:
Dbpath=D:\ data\ db
Logpath=D:\ data\ log\ mongodb.log
Open the cmd command line as an administrator, go to the D:\ mongodb\ bin directory, and enter the following command:
Mongod-config D:\ mongodb\ mongo.config-install-serviceName "MongoDB"
The result is stored in the log file mongodb.log, and it is found that the log has been successful.
The path is as follows: (1) run-> attachments-> Open the command line as an administrator
(2) d: (3) cd mongodb\ bin
3. Set up
Mongod.exe-bind_ip yourIPadress-logpath "C:\ data\ dbConf\ mongodb.log"-- logappend-- dbpath "C:\ data\ db"-- port yourPortNumber-- serviceName "YourServiceName"-- serviceDisplayName "YourServiceName"-- install
4. My computer needs mongod on to keep connecting to 27017, otherwise it will be cut off:
D:\ mongodb\ bin > mongo.exe
MongoDB shell version v3.4.7
Connecting to: mongodb://127.0.0.1:27017
2017-09-07T00:10:55.657+0800 W NETWORK [thread1] Failed to connect to 127.0.0.
: 27017 after 5000ms milliseconds, giving up.
2017-09-07T00:10:55.658+0800 E QUERY [thread1] Error: couldn't connect to se
Ver 127.0.0.1:27017, connection attempt failed:
Connect@src/mongo/shell/mongo.js:237:13
@ (connect): 1:6
Exception: connect failed
5. Configure the mongodb extension of php
(1) download php_mongo.dll
Http://windows.php.net/downloads/pecl/releases/mongo/
(2) phpinfo to view the php version
Architecture x86
Compiler MSVC9 (Visual C++ 2008) [that is, VC9 version]
Thread Safety enabled
64 bit
So download php_mongo-1.5.8-5.4-ts-vc9-x86.zip
(3) put it under the .php\ ext path
(4) set the path dependency of libsasl.dll
My computer right-click properties advanced settings advanced environment variables
Variable name Path variable value added; E:\ PROGRAM\ phpStudy\ php\ php-5.4.45
(5) restart Apache
(6) check whether there is a mongo section under PHPinfo
Test database
6. Management tools
Download rockmongo and put it in the www directory
Install MongoDB under unbuntu:
1. You are relatively familiar with the installation under unbuntu:
Sudo apt-get install mongodb
2. Turn off startup
Service mongodb start
Service mongodb stop
3. Start automatically by default
Pgrep mongo-l
4. Uninstall
Sudo apt-get-purge remove mongodb mongodb-clients mongodb-server
6. Enter mongo to enter shell command mode
7. Common commands:
Show dbs: displaying a list of databases
Show collections: displays the collection in the current database (similar to the table table in a relational database)
Show users: show all users
Use yourDB: switch the current database to yourDB
Db.help (): show database operation commands
Db.yourCollection.help (): displays the collection operation command, where yourCollection is the collection name
8. Database operation
(1) create a database
Use mydb
Db.createCollection ('mytable')
(2) insert data
There are two ways to insert data: insert and save.
Db.student.insert ({_ id:1,name:'x _ id, age: 1}) # _ optional
Db.student.save ({_ id:1,name: 'yearly, age: 2}) # _ id optional
In both ways, the _ id field in the inserted data can be left unwritten, and a unique _ id is automatically generated to identify this data.
The difference between insert and save is that when inserting the _ id field manually, if _ id already exists, insert does not do the operation, and save does the update operation; if you do not add the _ id field, both have the same function of inserting data
(3) insert multiple pieces of data
S = ["name:" z ", age:3}, {name:" a ", age:4}]
Similar to json
insert
Db.student.insert (s)
View
Db.student.find ()
Show collections
(4) find data
Db.youCollection.find (criteria, filterDisplay)
Criteria: query criteria, optional
FilterDisplay: filter and display part of the data, such as the specified column data, optional (when selected, the first parameter cannot be omitted; if the query condition is empty, {} can be used as a placeholder, such as the third sentence of the following example)
Example: db.student.find ({name:'z'})
(5) modify data
Db.youCollection.update (criteria, objNew, upsert, multi)
Criteria: the query condition of update, similar to the one after where in the sql update query
ObjNew: the object of update and some updated operators (such as $set) can also be understood as following set in a sql update query.
Upsert: if there is no record of update, whether to insert objNew,true is insert, default is false, do not insert.
Multi: mongodb defaults to false. Only the first record found is updated. If this parameter is true, multiple records found by condition will be updated. The default false modifies only the first piece of data that matches.
The first two are required parameters, and the last two are optional parameters
(condition, modify, insert, update all)
Example:
Db.student.update ({name:'a'}, {$set: {age: 100}}, false, true)
# is equivalent to: update student set age = 100where name ='a'
(6) Delete data
Db.student.remove ({name:'x'})
9. Quit
Exit/CTRL+C
10. Install the php PECL extension
(1) sudo apt-get install php-pear php5-dev
(2) install PECL package (take installing uploadprogress package as an example) the same is true when I install mongo
Sudo pecl install uploadprogress
(3) modify PHP.ini
Add extension=uploadprogress.so to php.ini (Ubuntu does not need to specify a path)
(4) restart Apache
Sudo / etc/init.d/apache2 restart
Reference link: http://blog.csdn.net/flyfish211222/article/details/51886787
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.