本文整理汇总了PHP中MongoCollection类的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection类的具体用法?PHP MongoCollection怎么用?PHP MongoCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MongoCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendMongo
function sendMongo($steamId, $type)
{
//function mongoConnect($steamId,$type,$collection){
switch ($type) {
case 1:
//gets the player Summaries
$fetch_pInfo = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?\t\tkey=238E8D6B70BF7499EE36312EF39F91AA&steamids={$steamId}";
break;
case 2:
//gets the players Game Library
$fetch_pInfo = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=238E8D6B70BF7499EE36312EF39F91AA&steamid={$steamId}&format=json";
break;
/*
case 3://gets the players achievements
//steam api for players achievements.
break;
case 4://may have to get other stats,
//will use this maybe for players over all steam rank.
break;
*/
}
//end switch data
$jsonO = file_get_contents($fetch_pInfo);
var_dump($jsonO);
$connection = new MongoClient("mongodb://alex:password@ds041643.mongolab.com:41643/steamdata");
$mongodb = $connection->selectDB('steamdata');
$collection = new MongoCollection($mongodb, 'gameLibrary');
//var_dump($connection);
//var_dump($collection);
$send = array();
$send["_id"] = $steamId;
$send["info"] = $jsonO;
$collection->insert($send);
}
示例2: findByArray
/**
* @unused?
* generalized mongo query
* @param array $query
* @param MongoCollection $collection
* @return array
* @throws modelException
*/
protected function findByArray($query = [], \MongoCollection $collection)
{
if (count($query) < 1) {
throw new modelException('array is required');
}
return iterator_to_array($collection->find($query));
}
示例3: mkonereg
function mkonereg($db, $colname, $grouparr)
{
$ops = array();
// $ops[] = ['$match' => $query];
// $ops[] = ['$sort' => ['year'=> -1, 'month'=> -1]];
$ops[] = ['$group' => $grouparr];
$option = ['allowDiskUse' => true];
//print_r($ops);
$collection = new MongoCollection($db, $colname);
echo "working on: {$colname} ... with";
$col2name = $colname . "_reg";
$col2 = new MongoCollection($db, $col2name);
print_r($grouparr['_id']);
makegrpIndex($db, $col2, $grouparr['_id']);
//print_r($ops);
try {
$cursor = $collection->aggregateCursor($ops, $option);
} catch (MongoException $e) {
echo "error message: " . $e->getMessage() . "\n";
echo "error code: " . $e->getCode() . "\n";
exit(1);
}
//$results = $cursor['result'];
foreach ($cursor as $result) {
//print_r($result[_id]);
$col2->insert($result['_id']);
}
}
示例4: doWrite
/**
* Write a message to the log.
*
* @param array $event Event data
* @return void
* @throws Zend\Log\Exception\RuntimeException
*/
protected function doWrite(array $event)
{
if (null === $this->mongoCollection) {
throw new RuntimeException('MongoCollection must be defined');
}
$this->mongoCollection->save($event, $this->saveOptions);
}
示例5: get
/**
* Fetches the object pointed to by a reference
*
* @param mongodb $db - Database to use.
* @param array $ref - Reference to fetch.
*
* @return array - Returns the document to which the reference refers
* or NULL if the document does not exist (the reference is broken).
*/
public static function get(MongoDB $db, $ref)
{
$ref = (array) $ref;
if (!isset($ref['$id']) || !isset($ref['$ref'])) {
return;
}
$ns = $ref['$ref'];
$id = $ref['$id'];
$refdb = null;
if (isset($ref['$db'])) {
$refdb = $ref['$db'];
}
if (!is_string($ns)) {
throw new MongoException('MongoDBRef::get: $ref field must be a string', 10);
}
if (isset($refdb)) {
if (!is_string($refdb)) {
throw new MongoException('MongoDBRef::get: $db field of $ref must be a string', 11);
}
if ($refdb != (string) $db) {
$db = $db->_getClient()->{$refdb};
}
}
$collection = new MongoCollection($db, $ns);
$query = ['_id' => $id];
return $collection->findOne($query);
}
示例6: dataBaseCall
function dataBaseCall($collectionName)
{
$m = new MongoClient();
$db = $m->selectDB('SocialMedia');
$collection = new MongoCollection($db, $collectionName);
$cursor = $collection->find();
return $cursor;
}
示例7: testPermissionSave
public function testPermissionSave()
{
$perm_coll = new \MongoCollection($this->db, "auth_permission");
$p1 = Permission::create("test_1", "desc");
$this->adapter->permissionSave($p1);
$this->assertNotEmpty($p1->permission_id);
$fetched_perm = $perm_coll->findOne(array('_id' => $p1->permission_id));
$this->assertEquals($fetched_perm['_id']->{'$id'}, $p1->permission_id);
}
示例8: connect
/**
* Connects to mongodb.
*
* @return \MongoCollection
*/
public function connect()
{
if (!$this->collection) {
$client = new \MongoClient($this->server);
$db = $client->selectDB($this->db);
$this->collection = $db->selectCollection('mc_recharge_card_profiles');
$this->collection->ensureIndex(array('uniqueness' => 1), array('unique' => true));
}
return $this->collection;
}
示例9: generateId
public function generateId(MongoCollection $collection)
{
$collection_name = $collection->getName();
$document = $this->collection->findAndModify(array('_id' => $collection_name), array('$inc' => array('_max_id' => 1)), null, array('new' => true));
if (!$document) {
$this->collection->insert(array('_id' => $collection_name, '_max_id' => $this->autoIncrement));
return $this->generateId($collection);
}
return $document['_max_id'];
}
示例10: find
/**
* @param QueryInterface $query
* @param ModelInterface $model
* @return ModelListInterface
* @throws NotSupportedFilterException
*/
public function find(QueryInterface $query, ModelInterface $model)
{
$queryArray = array();
foreach ($query->getFilters() as $filter) {
if (!in_array(get_class($filter), self::$supportedFilters)) {
throw new NotSupportedFilterException(sprintf('%s filter is not supported or unknown.', get_class($filter)));
}
$queryArray[$filter->getFieldName()] = $filter->getValue();
}
$list = new ModelList();
$cursor = $this->collection->find($queryArray);
if ($query->getLimit() !== null) {
$cursor->limit($query->getLimit());
}
if ($query->getOffset() !== null) {
$cursor->skip($query->getOffset());
}
foreach ($cursor as $doc) {
unset($doc['_id']);
/** @var ModelInterface $item */
$item = new $model();
$item->loadData($doc);
if ($item instanceof SavableModelInterface) {
$item->markAsStored();
}
$list->addListItem($item);
}
return $list;
}
示例11: doLog
/**
* Logs a message.
*
* @param string $message Message
* @param string $priority Message priority
*/
protected function doLog($message, $priority)
{
$document = array('message' => $message, 'priority' => $priority);
$event = new sfEvent($this, 'mongodblog.pre_insert');
$this->dispatcher->filter($event, $document);
$this->collection->insert($event->getReturnValue(), $this->options['save']);
}
示例12: save
/**
* Zapisuję dokonane zmiany w bazie
*
* @return void
*/
public function save()
{
$aMods = [];
// dla modelu z modułami
if ($this->aModules !== null) {
// obsługa modułów
foreach ($this->aModules as $mModule) {
if (!$mModule instanceof Module) {
continue;
}
$aChanges = $mModule->beforeSave();
$aMods[] = $mModule;
if (!empty($aChanges)) {
$this->mergeChanges($aChanges);
}
}
}
$aChanges = $this->getChanges();
// zapisuję jeśli się coś zmieniło
if (!empty($aChanges)) {
$this->oCollection->update(['_id' => $this->getId(true)], $this->getChanges());
$this->clearChanges();
// post save
foreach ($aMods as $oModule) {
$oModule->afterSave();
}
}
}
示例13: deleteExceedingQuota
public function deleteExceedingQuota($quota)
{
$threshold = 0.9 * $quota;
$currentSize = $this->getPictureTotalSize();
$counter = 0;
if ($currentSize > $threshold) {
$toPurge = $currentSize - $threshold;
// cleaning
$cursor = $this->collection->find(['-class' => 'picture'], ['storageKey' => true, 'size' => true])->sort(['_id' => 1]);
// starting from older pictures
$sum = 0;
foreach ($cursor as $item) {
if ($sum < $toPurge) {
$this->storage->remove($item['storageKey']);
$this->collection->remove(['_id' => $item['_id']]);
$sum += $item['size'];
$counter++;
} else {
// when we have deleted enough old pictures to reach the exceeding size to purge
break;
}
}
}
return $counter;
}
示例14: write
/**
* Write messages
*
* @return mixed|void
*/
public function write()
{
foreach ($this->messages as $message) {
$message['log'] = $this->format($message);
$this->collection->save($message);
}
}
示例15: count
/**
* Zwraca liczbę elementów
*
* @return int
*/
public function count()
{
if ($this->iCount === null) {
$this->iCount = $this->oColl->find($this->aQuery, $this->aFields)->count(true);
}
return $this->iCount;
}