Nếu bạn đã cài đặt MongoDB thì trước tiên hãy thử chạy mongod với tư cách là người dùng sudo, tôi đã gặp phải sự cố do không chạy mongod với tư cách là người dùng siêu cấp.
Tôi đã dán o / p cho cả hai lệnh ( mongod và sudo mongod ) ở dưới cùng, bạn cũng có thể kiểm tra điều đó nhưng
Lần đầu tiên thử cái này
sudo mongod
không phải cái này
mongod
Tôi đã cài đặt MongoDB trên MAC OS X Sierra 10.12.6 của mình bằng cách chạy lệnh sau theo trình tự.
brew update
brew install mongodb --devel
brew services start mongodb
sau đó tạo một thư mục mà quy trình mongod sẽ ghi dữ liệu vào đó, đây là tùy chọn vì quy trình mongod lấy nó theo mặc định, hãy xem hướng dẫn hữu ích này tại https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os -x /
sudo mkdir -p /data/db
Cuối cùng bắt đầu quy trình mongod như sau
sudo mongod
Oputput của các lệnh mongod (không thành công) và sudo mongod (thành công) trên thiết bị đầu cuối của tôi.
MacBook-Pro-2:appscheck admin$ mongod
2017-12-10T08:12:06.166+0530 I CONTROL [initandlisten] MongoDB starting : pid=2698 port=27017 dbpath=/data/db 64-bit host=MacBook-Pro-2.local
2017-12-10T08:12:06.166+0530 I CONTROL [initandlisten] db version v3.4.10
2017-12-10T08:12:06.166+0530 I CONTROL [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-12-10T08:12:06.166+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2n 7 Dec 2017
2017-12-10T08:12:06.166+0530 I CONTROL [initandlisten] allocator: system
2017-12-10T08:12:06.166+0530 I CONTROL [initandlisten] modules: none
2017-12-10T08:12:06.166+0530 I CONTROL [initandlisten] build environment:
2017-12-10T08:12:06.166+0530 I CONTROL [initandlisten] distarch: x86_64
2017-12-10T08:12:06.166+0530 I CONTROL [initandlisten] target_arch: x86_64
2017-12-10T08:12:06.166+0530 I CONTROL [initandlisten] options: {}
2017-12-10T08:12:06.166+0530 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2017-12-10T08:12:06.166+0530 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-12-10T08:12:06.166+0530 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-12-10T08:12:06.167+0530 I CONTROL [initandlisten] now exiting
2017-12-10T08:12:06.167+0530 I CONTROL [initandlisten] shutting down with code:100
MacBook-Pro-2:appscheck admin$ sudo mongod
Password:
2017-12-10T08:12:14.084+0530 I CONTROL [initandlisten] MongoDB starting : pid=2700 port=27017 dbpath=/data/db 64-bit host=MacBook-Pro-2.local
2017-12-10T08:12:14.084+0530 I CONTROL [initandlisten] db version v3.4.10
2017-12-10T08:12:14.084+0530 I CONTROL [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-12-10T08:12:14.084+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2n 7 Dec 2017
2017-12-10T08:12:14.084+0530 I CONTROL [initandlisten] allocator: system
2017-12-10T08:12:14.084+0530 I CONTROL [initandlisten] modules: none
2017-12-10T08:12:14.084+0530 I CONTROL [initandlisten] build environment:
2017-12-10T08:12:14.084+0530 I CONTROL [initandlisten] distarch: x86_64
2017-12-10T08:12:14.084+0530 I CONTROL [initandlisten] target_arch: x86_64
2017-12-10T08:12:14.084+0530 I CONTROL [initandlisten] options: {}
2017-12-10T08:12:14.084+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7680M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten]
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten]
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten]
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-12-10T08:12:14.560+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-12-10T08:12:14.707+0530 I INDEX [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2017-12-10T08:12:14.707+0530 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-12-10T08:12:14.719+0530 I INDEX [initandlisten] build index done. scanned 0 total records. 0 secs
2017-12-10T08:12:14.720+0530 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.4
2017-12-10T08:12:14.720+0530 I NETWORK [thread1] waiting for connections on port 27017
Sau đó, tôi mở thiết bị đầu cuối mới để bắt đầu truy vấn MongoDB , nó đã hoạt động.
MacBook-Pro-2:appscheck admin$ mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten]
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten]
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten]
2017-12-10T08:12:14.472+0530 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
> show dbs;
admin 0.000GB
local 0.000GB
> use practice
switched to db practice
>
Đó là nó.