mongodb-php

Calling a stored procedure via PHP in MongoDB

試著忘記壹切 提交于 2019-12-10 11:05:42
问题 Dear everybody who can help, I have this PHP > MongoDB problem, I want to call a stored procedure (stored in db.system.js collection) via PHP. I have no parameters, only a returning JSON object which looks like this: {"archived":[the number of the archived messages]} It works good in the shell on the database server, but when I try to call it via the PHP driver it just doesn't "say" anything... My code looks like this: $DB->execute( new MongoCode( "function () { return archiveMessages(); }" )

How can I use MongoDB in Kohana?

∥☆過路亽.° 提交于 2019-12-10 11:00:52
问题 Please, give me some startup guidance on how to use MongoDB in Kohana[v3.2]. I downloaded the Kohana Module from Mongo Module for kohana and have set up the MongoDB driver for PHP. Now I'm trying to create a new database and to save a record into it. 回答1: You Don't actually need the MangoDB module for Kohana that you linked to. You can just use PHP's MongoDB Native Driver. The mongo query language is pretty simple, if you know some MySQL then this page would help... http://www.php.net/manual

mongodb limit in the embedded document

大城市里の小女人 提交于 2019-12-09 06:22:22
问题 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

Is it ideal that MongoDB is using 150 MB memory?

假装没事ソ 提交于 2019-12-09 06:12:44
问题 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

How to update embedded document in MongoDB with Doctrine ODM

孤街浪徒 提交于 2019-12-08 12:22:32
问题 I'm unable to find how to update embedded documents with Doctrine Mongo ODM in Symfony2. I have a class called Page with many embedded documents "Comments" and I want to use createQueryBuilder to update specific comment. Here is a simple class that I have: class Page { protected $id; /** @MongoDB\EmbedMany */ private $pageComment = array(); } I searched the whole internet, but I don't see to find any info on how to update subdocuments of a document with Doctrine ODM query builder. I will be

MongoDB Aggregate Variable to create Multiple Fields?

拟墨画扇 提交于 2019-12-08 04:28:37
问题 Given the following query, what is the best method to use $$priceToInflationRatio to help create multiple calculated fields? From what I have read on $let, it appears to only work for creating a single field -- I would like to use the variables across my entire $project section. Is that possible? db.books.aggregate([ {$project: { 'priceInflationresult': { $let: { vars: { 'priceToInflationRatio': { $multiply: [{'$divide': [{'$subtract': ['$price', 1]}, 5]}, 10] } }, in: { '$cond': [ {'$gt': ['

Sort subfields with unknown parent

我是研究僧i 提交于 2019-12-08 03:56:14
问题 I have a schema like this: { "_id" : "555", "connections" : [ { "id" : 111 "time" : 1456439249 }, { "id" : 222 "time" : 1556412345 } ... } "users" : [ "111" : { "id" : 111 "name" : "Michael" }, "222" : { "id" : 222 "name" : "Jim" } ... } I want to get sorted connections by time and users data. I'm trying with this: db.getCollection('mycollecion') .find( {'_id' : '555'}, {'_id' : 0, 'connections' : 1, 'users' : 1} ).sort({'connections.time' : 1}) Probably "connections.time" is not the correct

unable to save PHP objects in mongodb

浪尽此生 提交于 2019-12-07 13:32:55
问题 Getting 'zero-length keys are not allowed' FATAL error while saving object. Is it due to presence of __construct() ? I believe PHP object is allowed in save() method. class Address{ private $name; private $company; private $zip; public function __construct($name,$company,$zip){ $this->name = $name; $this->company = $company; $this->zip = $zip; } } $newAddress = new Address("james","google",678); print_r($newAddress); // Address Object ( [name:Address:private] => james [company:Address:private

how to integrate mongodb library in codeigniter for database connection with mongodb

喜夏-厌秋 提交于 2019-12-07 07:02:56
问题 I am creating application with codeigniter and mongodb database. As codeigniter doesn't contain mongodbs driver, I have used built in library to connect with mongodb. I have used this link to create mongodb configration file and Mongo_db library. The configration file is like application\config\mongodb: <?php $config['default']['mongo_hostbase'] = 'localhost:27017'; $config['default']['mongo_database'] = 'test'; $config['default']['mongo_username'] = ''; $config['default']['mongo_password'] =

MongoDB 2.6 Index set up, query using $or, $in, with limit and sort

大兔子大兔子 提交于 2019-12-07 02:38:23
问题 I have a somewhat complex query that is very critical to my application. $cur = $col->find( array ( '$or' => array( array('owner' => $my_id), array('owner' => array('$in' => $friends), 'perm.type' => array('$in' => array('P', 'F'))), array('owner' => array('$in' => $friends), 'perm.list' => $my_id) ) ) )->limit(10)->skip(0)->sort(array('ca' => -1)); The intention is to find the first 10 posts, sorted by their create time in desc order, which are: a). made by myself, or b). made by my friends