mongodb-php

MongoDB shell's db.stats() in php and python

我是研究僧i 提交于 2019-12-04 03:34:09
I can see the statistics from Mongo shell as db.stats() or db.collection_name.stats() How do I view statistics of a database, or of a collection, from PHP and Python. EDIT : I have done it in PHP but still cant do it in Python. Help? Sagar Hatekar This is how you do it in Python if you are using the PyMongo driver: connection = pymongo.Connection(host = "127.0.0.1", port = 27017) db = connection["test_db"] test_collection = db["test_collection"] db.command("dbstats") # prints database stats for "test_db" db.command("collstats", "test_collection") # prints collection-level stats for "test

Using Mongodb ObjectID as a document ID?

梦想的初衷 提交于 2019-12-04 01:03:40
问题 I'm trying to make a board with mongoDB. I want to assign document ID with ObjectID. If a user can access to a document page by http://www.example.com/4easdf123123 where "4easdf123123" is a mongoDB ObjectID. Is there any possible security threat, If I use and show mongo ObjectID in URL and using it as a document id? And any suggestion with assigning document ID with mongoDB? 回答1: That doesn't look like a MongoDB ObjectID -- an ObjectID is 12 bytes of binary data, and when rendered as a

Decoding JSON using PHP from Mongo

泪湿孤枕 提交于 2019-12-03 21:37:18
I've already looked at this thread: PHP decode nested JSON and haven't managed to use it to solve my problem. I am currently grabbing a JSON object from Mongo, and I'm having issues grabbing information from nested objects. { "adminLevel" : 200, "chat" : true, "clans" : [ BinData(0,"wcXHR577OVBXfy9JwEf5gQAAAAAAAAAAAAAAAAAAAAAAAAAAAA") ], "experience" : NumberLong(70003), "kitNew" : { "converted" : true, "items" : { "ak47" : { "killCount" : 5, "selected" : false, "unlocked" : 1 }, "hub-knife" : { "selected" : false }, "assault" : { "selected" : false, "unlocked" : 1 }, "pistol" : {

MongoDB PHP using $in with array

…衆ロ難τιáo~ 提交于 2019-12-03 14:32:34
I'm using MongoDB and PHP and trying to do a $in based on a generated array. When I specify the same array manually, it works, but when I build it, it return any results with the same data. There's what I have: $settings = array(); foreach($items as $item) { $settings[] = $item['id']; } //Settings is the same as this $setting2 = array(1,2,3,4,5,6,7,8); //This returns no results $cursor = $collection->find(array('status' => 0, 'sid' => array('$in' => $settings))); //This does return results $cursor = $collection->find(array('status' => 0, 'sid' => array('$in' => $setting2))); I've checked using

MongoConnectionException - No candidate servers found

倖福魔咒の 提交于 2019-12-03 13:59:36
I am developing a PHP web application using a MongoDB replicaset to store my data. I occasionally receive the following error: Fatal error: Uncaught exception 'MongoConnectionException' with message 'No candidate servers found' I have a 3 member Mongo replica set with 1 arbiter rs0:PRIMARY> rs.status() { "set" : "rs0", "date" : ISODate("2013-01-30T01:04:04Z"), "myState" : 1, "members" : [ { "_id" : 0, "name" : "JenEricsMacPro.local:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 844478, "optime" : Timestamp(1359507378000, 1), "optimeDate" : ISODate("2013-01-30T00:56:18Z")

How do you get the string value of a MongoID using PHP?

余生颓废 提交于 2019-12-03 09:30:21
问题 After doing an insert I want to pass the object to the client using json_encode(). The problem is, the _id value is not included. $widget = array('text' => 'Some text'); $this->mongo->db->insert($widget); If I echo $widget['_id'] the string value gets displays on the screen, but I want to do something like this: $widget['widgetId'] = $widget['_id']->id; So I can do json_encode() and include the widget id: echo json_encode($widget); 回答1: Believe this is what you're after. $widget['_id']->{'$id

Is it ideal that MongoDB is using 150 MB memory?

◇◆丶佛笑我妖孽 提交于 2019-12-03 07:44:41
This is the first project by me which is using MongoDB. I have hosted it on a linode (a VPS which uses XEN) and I'm checking memory usage with "top". The mongod process seem to use around 150 MB of memory. There were no connections to it when I checked. I use RockMongo to administer it. My main database stats are - Size - 464m Storage Size - 83.99m Data Size - 66.4m Index Size - 49.33m Collections - 5 Objects - 584850 A lot of queries happen when the cron job is running, around 75 per minute or even more. But, as I said earlier, when I checked the memory usage, there were no connections.

mongodb limit in the embedded document

偶尔善良 提交于 2019-12-03 07:16:28
I need to create a message system, where a person can have a conversation with many users. For example I start to speak with user2, user3 and user4, so anyone of them can see the whole conversation, and if the conversation is not private at any point of time any of participants can add any other person to the conversation. Here is my idea how to do this. I am using Mongo and my idea is to use dialog as an instance instead of message. The schema is listed as follows: { _id : ...., // dialog Id 'private' : 0 // is the conversation private 'participants' : [1, 3, 5, 6], //people who are in the

Find a document with ObjectID in mongoDB

ε祈祈猫儿з 提交于 2019-12-03 03:41:46
问题 When I inserted some documents into a collection (without an ObjectID) mongoDB adds its own ObjectIDs. I want to query a document by its unique ObjectID. $db->collection_name->find(array('_id'=>'4e49fd8269fd873c0a000000'))); It does not work either with prefix of MongoID or ObjectID in front of '4e49fd8269fd873c0a000000'. What is the proper way to query by ObjectID with mongoDB in PHP? 回答1: Pretty sure you have to use a MongoId object, eg $item = $collection->findOne(array( '_id' => new

How do you get the string value of a MongoID using PHP?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 01:09:02
After doing an insert I want to pass the object to the client using json_encode(). The problem is, the _id value is not included. $widget = array('text' => 'Some text'); $this->mongo->db->insert($widget); If I echo $widget['_id'] the string value gets displays on the screen, but I want to do something like this: $widget['widgetId'] = $widget['_id']->id; So I can do json_encode() and include the widget id: echo json_encode($widget); Believe this is what you're after. $widget['_id']->{'$id'}; Something like this. $widget = array('text' => 'Some text'); $this->mongo->db->insert($widget); $widget[