本文整理汇总了PHP中Illuminate\Support\Facades\DB::getMongoDB方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::getMongoDB方法的具体用法?PHP DB::getMongoDB怎么用?PHP DB::getMongoDB使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\DB
的用法示例。
在下文中一共展示了DB::getMongoDB方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: projectInfo
public function projectInfo($name)
{
/** @var Database $db */
$db = DB::getMongoDB();
$nodes = $db->nodes->find(['type' => ['$in' => ['project_module', 'project_theme', 'project_core', 'project_distribution', 'project_theme_engine', 'project_drupalorg']], 'field_project_machine_name' => $name])->toArray();
if (count($nodes) == 0) {
abort(404);
}
$node = reset($nodes);
return $node;
}
示例2: cijobsRefresh
public function cijobsRefresh(JobStatusService $job_status_service)
{
$job = $job_status_service->getJobStatus('pift_ci_jobs', function () {
/** @var Database $db */
$db = DB::getMongoDB();
$last_job = $db->pift_ci_jobs->findOne([], ['sort' => ['updated' => -1], 'limit' => 1]);
return $last_job->updated;
});
if (!empty($job->queued)) {
return response()->json(['message' => 'The request is already queued. You should see updates soon.'])->setStatusCode(406);
}
$req = new PiftCiJobCollectionRequest(['sort' => 'updated', 'direction' => 'DESC']);
$options = ['last_updated' => $job->last_updated];
$this->dispatch(new RetrievePiftCiJobCollectionJob($req, $options));
$job->queued = true;
$job->save();
return response()->json(['message' => 'We have queued the request. You should see updates soon.'])->setStatusCode(202);
}
示例3: handle
public function handle(JobStatusService $job_status_service)
{
$job = $job_status_service->getJobStatus('pift_ci_jobs', function () {
/** @var Database $db */
$db = DB::getMongoDB();
$last_job = $db->pift_ci_jobs->findOne([], ['sort' => ['updated' => -1], 'limit' => 1]);
return $last_job->updated;
});
if (!empty($job->queued)) {
$this->error('The request is already queued. You should see updates soon.');
return 1;
}
$req = new PiftCiJobCollectionRequest(['sort' => 'updated', 'direction' => 'DESC']);
$options = ['last_updated' => $job->last_updated];
$this->dispatch(new RetrievePiftCiJobCollectionJob($req, $options));
$job->queued = true;
$job->save();
$this->line('The request is now queued. You should see updates soon.');
return 0;
}
示例4: projectIssueCount
public function projectIssueCount(Request $request)
{
/** @var Database $db */
$db = DB::getMongoDB();
$match = ['type' => 'project_issue'];
if ($request->input('open_issues')) {
$match['field_issue_status'] = ['$in' => array_map(function ($value) {
return (string) $value;
}, static::$openIssueStatus)];
}
$issues = $db->nodes->aggregate([['$match' => $match], ['$group' => ['_id' => ['project' => '$field_project.id'], 'count' => ['$sum' => 1]]], ['$sort' => ['count' => -1]], ['$limit' => 200]])->toArray();
$ret = [];
foreach ($issues as $issue) {
$project = $db->nodes->findOne(['_id' => $issue->_id->project]);
if ($project) {
$ret[] = ['_id' => $project['nid'], 'title' => $project['title'], 'machine_name' => $project['field_project_machine_name'], 'type' => $project['type'], 'value' => $issue->count];
}
}
return response()->json($ret);
}
示例5: projectsGrowth
public function projectsGrowth()
{
/** @var Database $db */
$db = DB::getMongoDB();
$nodes = $db->nodes->aggregate([['$match' => ['type' => ['$in' => ['project_module', 'project_theme', 'project_core', 'project_distribution', 'project_theme_engine']]]], ['$project' => ['_id' => 0, 'created' => 1, 'type' => 1, 'tsday' => ['$mod' => ['$created', 86400]]]], ['$project' => ['_id' => 0, 'type' => 1, 'ts' => ['$subtract' => ['$created', '$tsday']]]], ['$group' => ['_id' => ['day' => '$ts', 'project_type' => '$type'], 'count' => ['$sum' => 1]]], ['$sort' => ['_id.day' => 1]]]);
$projects = ['project_module' => [], 'project_theme' => [], 'project_core' => [], 'project_distribution' => [], 'project_theme_engine' => []];
$last_timestamps = ['project_module' => 0, 'project_theme' => 0, 'project_core' => 0, 'project_distribution' => 0, 'project_theme_engine' => 0];
$min_timestamp = mktime(0, 0, 0, 1, 1, 2000);
foreach ($nodes as $node) {
$type = $node->_id->project_type;
// We can just save the last timestamp per each project type as the
// list is sorted by timestamp anyway.
$last_timestamps[$type] += $node->count;
// We don't return data for before 2000.
if ($node->_id->day < $min_timestamp) {
continue;
}
$projects[$type][date('Y-m-d', $node->_id->day)] = $last_timestamps[$type];
}
return response()->json($projects);
}
示例6: handle
public function handle(JobStatusService $job_status_service)
{
$type = $this->argument('type');
$job = $job_status_service->getJobStatus('nodes-' . $type, function () use($type) {
/** @var Database $db */
$db = DB::getMongoDB();
$last_job = $db->nodes->findOne([], ['sort' => ['changed' => -1], 'type' => $type, 'limit' => 1]);
return $last_job->changed;
});
if (!empty($job->queued)) {
$this->error('The request is already queued. You should see updates soon.');
return 1;
}
$req = new NodeCollectionRequest(['type' => $type, 'sort' => 'changed', 'direction' => 'DESC']);
$options = ['last_updated' => $job->last_updated, 'type' => $type];
$this->dispatch(new RetrieveNodeCollectionJob($req, $options));
$job->queued = true;
$job->save();
$this->line('The request is now queued. You should see updates soon.');
return 0;
}
示例7: deleteCollection
/**
* @param string $collectionName
* @return bool
*/
public function deleteCollection($collectionName)
{
$dbResponse = DB::getMongoDB()->dropCollection($collectionName);
return isset($dbResponse['ok']) ? (bool) $dbResponse['ok'] : false;
}
示例8: userCountryGrowth
public function userCountryGrowth()
{
/** @var Database $db */
$db = DB::getMongoDB();
$users = $db->users->aggregate([['$project' => ['_id' => 0, 'created' => 1, 'field_country' => 1, 'tsday' => ['$mod' => ['$created', 86400]]]], ['$project' => ['_id' => 0, 'field_country' => 1, 'ts' => ['$subtract' => ['$created', '$tsday']]]], ['$group' => ['_id' => ['day' => '$ts', 'country' => '$field_country'], 'count' => ['$sum' => 1]]], ['$sort' => ['_id.day' => 1]]]);
$users_count = [];
$last_timestamps = [];
$min_timestamp = mktime(0, 0, 0, 1, 1, 2000);
foreach ($users as $user) {
$country = $user->_id->country;
if (!$country) {
$country = "na";
}
$country = strtolower(str_replace(" ", "-", $country));
if (!isset($last_timestamps[$country])) {
$last_timestamps[$country] = 0;
}
if (!isset($users_count[$country])) {
$users_count[$country] = [];
}
// We can just save the last timestamp per each project type as the
// list is sorted by timestamp anyway.
$last_timestamps[$country] += $user->count;
// We don't return data for before 2000.
if ($user->_id->day < $min_timestamp) {
continue;
}
$users_count[$country][date('Y-m-d', $user->_id->day)] = $last_timestamps[$country];
}
return response()->json($users_count);
}