test.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace loyalsoft;
  3. include __DIR__ . '/main.php';
  4. //var_dump(__DIR__);
  5. echoLine("phpver: " . PHP_VERSION . PHP_EOL);
  6. echoLine("tsDay:" . totalDays());
  7. //SelfChecker::CheckAll();
  8. //
  9. //set_time_limit(15); # 设置执行超时时间
  10. //
  11. //$cfg = config::Inst();
  12. //$mu = new MongoUtil();
  13. //$manager = $mu->conn($cfg->mongodb);
  14. //if ($manager === false) {
  15. // CLog::err("MongoDB连接异常!");
  16. //}
  17. // select
  18. $collection = 'test.ylsj2019taptap';
  19. $filter = ['key' => ['$regex' => '.*-g$']];
  20. $opt = MongoUtil::QueryOptionBuilder()->limit(3)->projection(['key' => 1, 'name' => '$value.baseInfo.name'])
  21. ->sort(["value.baseInfo.level" => -1]);
  22. $cursor = gMongo()->find($collection, $filter, $opt->GetOption());
  23. if (false === $cursor) {
  24. exit("查询失败");
  25. }
  26. //foreach ($cursor as $document) {
  27. // var_dump($document);
  28. //}
  29. // insert
  30. //$collection = "foo.bar";
  31. //$addArr = ['name' => "王刚1", 'age' => 37];
  32. //CLog::Assert("insert", gMongo()->insert($collection, $addArr), "插入数据");
  33. //
  34. //// delete
  35. //$collection = "foo.bar";
  36. //$deletFilter = ['name' => "王刚1"];
  37. //echoLine("删除" . gMongo()->delete($collection, $deletFilter) . "条");
  38. // update
  39. $collection = "foo.bar";
  40. $updateFilter = ['Name' => "王刚(wanggangzero@qq.com)1"];
  41. $updateArr = ['Name' => "王刚(wanggangzero@qq.com)1", 'Age' => 37, '性别' => "男", '爱好' => '女'];
  42. echoLine("修改" . gMongo()->update($collection, $updateFilter, $updateArr, true, false));
  43. //
  44. echoLine("---");