public function run() { $candidate = new Candidate(); $collection_name = $candidate->getCollectionName(); $connection = \Hexcores\MongoLite\Connection::instance(); $connection->collection($collection_name)->drop(); $faker = Factory::create(); $parties = mongo_lite('party')->all(); for ($i = 0; $i < 20; $i++) { $residency = $faker->state() . ' / ' . $faker->city(); $constituency = $faker->city() . ' / ' . $faker->cityPrefix() . ' / ' . $faker->state(); $pcode = $this->getRandomPcode(); $data = ['name' => $faker->name, 'gender' => $faker->randomElement(['male', 'female']), 'legislature' => $faker->randomElement(['amyotha_hluttaw', 'pyithu_hluttaw', 'region', 'state']), 'nrc' => $faker->bothify('##/???(N)######'), 'dob' => new \MongoDate($faker->dateTime($max = 'now')->format('U')), 'education' => $faker->words($nb = rand(0, 4)), 'occupation' => $faker->words($nb = rand(0, 4)), 'religion' => $faker->randomElement(['Buddhism', 'Christian', 'Islam', 'Hindu']), 'party_id' => $this->getPartyId($parties), 'residency' => ['type' => $residency, 'name' => $residency . ' name', 'ST_PCODE' => $pcode['ST_PCODE'], 'DT_PCODE' => $pcode['DT_PCODE'], 'count' => $faker->randomNumber(5)], 'constituency' => ['type' => $constituency, 'name' => $faker->word(), 'ST_PCODE' => $pcode['ST_PCODE'], 'DT_PCODE' => $pcode['DT_PCODE'], 'count' => $faker->randomNumber(5)], 'father' => ['name' => $faker->name, 'religion' => $faker->randomElement(['Buddhism', 'Christian', 'Islam', 'Hindu'])], 'mother' => ['name' => $faker->name, 'religion' => $faker->randomElement(['Buddhism', 'Christian', 'Islam', 'Hindu'])]]; $candidate->getCollection()->insert($data); } }
/** * Fire the command */ public function fire() { $collection = $this->input->getArgument('name'); $this->info('Drop the collection ' . $collection); mongo_lite($collection)->collection()->drop(); }
<?php require __DIR__ . '/../vendor/autoload.php'; // Configure Mongo Lite Connection Hexcores\MongoLite\Connection::connect('localhost', 27017, 'mongo_lite'); $users = mongo_lite('users')->delete(['name' => 'Nyan Lynn Htut']); var_dump($users); exit; foreach ($users as $user) { echo $user->name . '</br>'; echo $user->job . '</br>'; echo $user->toJson() . '<br>'; echo '<hr>'; }
public function setCollection($collection) { return mongo_lite($collection); }
<?php require __DIR__ . '/../vendor/autoload.php'; // Configure Mongo Lite Connection Hexcores\MongoLite\Connection::connect('localhost', 27017, 'mongo_lite'); $nyan = ['name' => 'John', 'age' => 22]; mongo_lite_insert('test_increment', $nyan); mongo_lite('test_increment')->increment(['name' => 'John'], 'age'); $john = mongo_lite('test_increment')->first(['name' => 'John']); var_dump($john); exit;
/** * Create ensure index for collection. * * @param string $collection * @param array $indexs * @return [type] */ function mongo_lite_index($collection, $indexs) { $collection = mongo_lite($collection); return $collection->index($indexs); }