-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbMongo.php
67 lines (60 loc) · 1.42 KB
/
dbMongo.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
$conn = new Mongo();
$db = $conn->selectDB('test');
$db->numbers->drop();
for($i=0 ; $i < 250000;$i++){
$db->numbers->save(array('num'=> $i));
}
echo 'ADDED . <br/>';
$results = $db->numbers->find()->limit(2);
foreach($results as $document){
print_r ($document);
}
echo "<br/>Sap xep giam dan<br/>";
/* Sort */
$results = $db->numbers->find()->limit(2)->skip(20)->sort(array('num'=> -1));
foreach($results as $document){
print_r ($document);
}
echo "<br/>Test Viec so sanh :<br/>";
echo "<br/>Danh sach cac so nho hon 15<br/>";
/** Cac bieu thuc so sanh */
/*
* $gt >
* $lt <
* $gte >=
* $lte <=
*/
$results = $db->numbers->find(
array(
'num' => array('$lt'=>15)
)
);
foreach($results as $document){
print_r ($document) . "<br/>";
}
/**
* Working with Array
*/
/**
* $all
* $in
* $nin
* $size
*/
/**
* Test Indexes
*/
echo "<br/>Test KHONG Indexes voi ham explain() (de y thoi gian run) <br/>";
print_r($db->numbers->find(
array('num'=> array('$gt' => 50000, '$lt' =>50002)))->explain());
echo "<br/>Ket thuc test KHONG INDEXES<br/>";
/**
* Test co indexes
*/
echo "<br/>Test CO Indexes voi ham explain() (de y thoi gian run)<br/>";
$db->numbers->ensureindex(array('num'=> -1));
print_r($db->numbers->find(
array('num'=> array('$gt' => 50000, '$lt' =>50002)))->explain());
echo "<br/>Ket thuc test CO INDEXES<br/>";
?>