IT. Expert System.

PHP

Creates a database reference


MongoDB::createDBRef

(PECL mongo >=0.9.0)

MongoDB::createDBRefCreates a database reference

Description

public array MongoDB::createDBRef ( string $collection , mixed $a )

This method is a flexible interface for creating database refrences (see MongoDBRef).

Parameters

collection

The collection to which the database reference will point.

a

Object or _id to which to create a reference. If an object or associative array is given, this will create a reference using the _id field.

Return Values

Returns a database reference array.

Examples

Example #1 MongoDB::createDBRef() example

Example demonstrating how to programatically create a DB reference array from a document.

<?php

$articles 
$db->articles;

$article = array(
 
'title' => 'Test article',
 
'description' => 'Test article description'
);

$articles->insert($article);
$ref $db->createDBRef('articles'$article);

print_r($article);
print_r($ref);
?>

The above example will output something similar to:

  Array  (   [title] => Test article   [description] => Test article description   [_id] => MongoId Object    (    )  )  Array  (   [$ref] => articles   [$id] => MongoId Object    (    )  )  

Now the $ref can be stored on another document and retrieved later with MongoDB::getDBRef() or MongoCollection::getDBRef().

Example #2 MongoDB::createDBRef() example

Example demonstrating how to programatically create a DB reference from just an id.

<?php

$id 
= new MongoId('47cc67093475061e3d9536d2');
$ref $db->createDBRef('articles'$id);
?>


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 63 / 158746600. Delta: 0.03117 с