15 tháng 11 2014

Mongdb 101 Part 1

Create new collection:

db.users.insert({username:"beckerbao"})

Update or add new element (reference link: http://docs.mongodb.org/manual/core/write-operations-introduction/)
db.users.update({username:"beckerbao"},{$set,{country:"vietnam"}})
Add 1 more item to array:
  1. Create country with array type

    db.users.update({username:"beckerbao"},{$set,{country:["vietnam"]}})
  2. Add new item

    db.users.update({username:"beckerbao"},{$addToSet,{country:["usa"]}})

Delete an item in collection:
db.users.update({username:"beckerbao"},{$unset,{country:1}})

08 tháng 11 2014

PHP Driver vs Mongodb: Can not working (WAMP)



This is the first time i have installed php driver with mongodb. It make me frustrated but the problem is solved. There are 2 errors message in php_error_log i have found:

  1. 'php_mongo.dll' - The specified module could not be found.
  2. PHP Warning:  PHP Startup: mongo: Unable to initialize module.......These options need to match

The first message mean: your php driver is not correct version with mongodb. How to know the correct version? When you download a bulk of files php driver, all the file will like this:


  • php_mongo-1.5.7-5.4-vc9.dll
  • php_mongo-1.5.7-5.4-vc9-nts.dll
  • php_mongo-1.5.7-5.4-vc9-x86_64.dll
  • php_mongo-1.5.7-5.4-vc9-nts-x86_64.dll


Number "1.5.7" is the version of php driver, we don't need care about it. Next "5.4" is php version on your computer, "vc9" i guess it is build in version of php driver. The last but not least "nts" is "none theard safe", you can check your php is "thread safe" or "none thread safe" but check php[x].exe if it is "php5ts.exe" it is "thread safe" and vice versa.

So pick the correct file to install, and if you see the second message you need to try another "vc".

Good luck!!!!