Install MongoDB + phpMongoDriver in Mac OSX High Sierra

Posted by nopsled
2018.09.13 16:25 데이터베이스

 brew install mongodb 

First, you have to install mongodb.


nopsled@smleeo3o:~/dump (=`ω´=)$ php -v

PHP 7.1.7 (cli) (built: Jul 15 2017 18:08:09) ( NTS )

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies 



Second, check your php version. this example's php version is 7.1.


 brew tap kyslik/php

 brew install php71-mongodb


Third, we have to install php MongoDriver 7.1



nopsled@smleeo3o:~ (=`ω´=)$ cd /usr/local/Cellar/php71-mongodb/1.4.0

nopsled@smleeo3o:/usr/local/Cellar/php71-mongodb/1.4.0 (=`ω´=)$ ls

INSTALL_RECEIPT.json  mongodb.so*

nopsled@smleeo3o:/usr/local/Cellar/php71-mongodb/1.4.0 (=`ω´=)$ cp /etc/php.ini.default /etc/php.ini 


Check mongodb.so file and copy your /etc/php.ini.default to /etc/php.ini.


 878 ; ... or with a path:

 879 ;

 880 ;   extension=/path/to/extension/msql.so

 881 ;

 882     extension=/usr/local/Cellar/php71-mongodb/1.4.0/mongodb.so

 883 ; If you only provide the name of the extension, PHP will look for it in its

 884 ; default extension directory.

 885 ;

 886 ; Windows Extensions 

And you have to add mognodb.so files location in /etc/php.ini.


 nopsled@smleeo3o:/usr/local/Cellar/php71-mongodb/1.4.0 (=`ω´=)$ sudo apachectl restart

restart your apache.


이 댓글을 비밀 댓글로

[mongodb] how to find dictionary not null

Posted by nopsled
2018.04.30 18:17 데이터베이스

{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test@gmail.com",

    "name" : "test",

    "authType" : "google",

    "loc" : {

        "country" : "US"

    }

},


{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test2@gmail.com",

    "name" : "test2",

    "authType" : "google",

    "loc" : {}

},


{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test3@gmail.com",

    "name" : "test3",

    "authType" : "google",

    "loc" : {}

},


{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test4@gmail.com",

    "name" : "test4",

    "authType" : "google",

    "loc" : {

        "country" : "US"

    }

}


You have to know object's dictionary key.


If you want find loc(dictionary) not null data, using next query.


db.users.find({"loc.country":{$exists:true}}) 



debug result

{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test@gmail.com",

    "name" : "test",

    "authType" : "google",

    "loc" : {

        "country" : "US"

    }

},

{

    "_id" : ObjectId("5a129bde1c6fcc3ea4d21db0"),

    "email" : "test4@gmail.com",

    "name" : "test4",

    "authType" : "google",

    "loc" : {

        "country" : "US"

    }

}


이 댓글을 비밀 댓글로

mongodb not authorized? how to create database in mongodb

Posted by nopsled
2018.04.18 11:01 데이터베이스

[root@dataking01 data]# mongo

MongoDB shell version v3.4.9

connecting to: mongodb://127.0.0.1:27017

MongoDB server version: 3.4.9

> use testdb

switched to db testdb

> db.createCollection("test_collection")

{

"ok" : 0,

"errmsg" : "not authorized on testdb to execute command { create: \"test_collection\" }",

"code" : 13,

"codeName" : "Unauthorized"

}

>


위와 같이 authorized가 안되어 있어서 컬렉션도 못만들고 난리가 났다.



[root@dataking01 data]# ps -ef | grep mongo

root     11876     1  0 10:57 ?        00:00:01 /usr/bin/mongod --auth -f /etc/mongod.conf

root     12127  8518  0 11:01 pts/0    00:00:00 grep mongo

[root@dataking01 data]# kill -9 11876

[root@dataking01 data]# 


서비스 확인해주고 11876 죽여준다음에


[root@dataking01 data]# /usr/bin/mongod -f /etc/mongod.conf

about to fork child process, waiting until server is ready for connections.

forked process: 12173

child process started successfully, parent exiting

[root@dataking01 data]# 


--auth flag 빼버리고 mongodb를 시작해준다.


그리고 mongo로 접속해서 use database_name, db.createCollection("collection_name") 해주면 된다.


이거 했다고해서 --auth flag를 다시 넣어주는거 깜빡하지말자.. 골로간다



[root@dataking01 data]# ps -ef | grep mongo

root     12173     1  0 11:02 ?        00:00:00 /usr/bin/mongod -f /etc/mongod.conf

root     12232  8518  0 11:03 pts/0    00:00:00 grep mongo

[root@dataking01 data]# kill -9 12173

[root@dataking01 data]#

[root@dataking01 data]#

[root@dataking01 data]# /usr/bin/mongod --auth -f /etc/mongod.conf

about to fork child process, waiting until server is ready for connections.

forked process: 12278

child process started successfully, parent exiting

[root@dataking01 data]# 


--auth flag를 줘야 혹여나 안털린다


오늘의 삽질 끝.

이 댓글을 비밀 댓글로