-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconMongoDB.php
More file actions
executable file
·54 lines (41 loc) · 960 Bytes
/
conMongoDB.php
File metadata and controls
executable file
·54 lines (41 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/*
http://moleculax.com.ve
*/
require 'vendor/autoload.php';
$cn = (new MongoDB\Client("mongodb://127.0.0.1:27017"))->dbname->BDatos;
if($cn==true) {
echo "RESULTADOS DE LA CONSULTA:<br>"; //porque no hubo excepciones
}
$client = new MongoDB\Client();
$nom = $client->BDatos->datos;
//datos a insertar
$seedData = array(
array(
'ci' => '333',
'nombre' => 'DATO 01'
),
array(
'ci' => '1980',
'nombre' => 'DATO 02',
),
array(
'ci' => '1990',
'nombre' => 'DATO 03',
),
);
//inserta los datos
$nom->insertMany($seedData);
//actualiza datos
$nom->updateOne(
array('ci' => '1980'),
array('$set' => array('nombre' => 'DATO ACTUALIZADO'))
);
//muestra en pantalla los datos
$cursor = $nom->find();
foreach($cursor as $doc) {
echo 'Cedula: ' .$doc['ci'];
echo ',Nombre: ' .$doc['nombre'];
echo"<br>";
}
?>