Category : mongodb

i am NOT getting result thought the data is there in DB $conditions = collect($this->getColumns())->map(function ($column, $key) use ($keyword, $or_conditions) { return $or_conditions[] = [ $column => [ ‘$regex’ => "$keyword", ‘$options’ => ‘i’ ], ]; }); $final_or_condition = [ ‘$or’ => $conditions->toArray() ]; $this->collection = $this->collection->whereRaw($final_or_condition); when i search in Datatable input field on ..

Read more

In my project, I use Laravel 8 with Mongodb as my database, and jenssegers/laravel-mongodb as its driver. Let say I have a collection named products which has relationship embedsOne to vendors. when I create a new product, how can I insert existing vendor to this new product? I tried the following $vendor = Vendor::find($request->vendor); $product ..

Read more

i am having collection of employee assosiated with company use IlluminateDatabaseEloquentModel; use JenssegersMongodbEloquentModel as Eloquent; class Employee extends Eloquent { protected $casts = [ ‘has_pp’ => ‘Boolean’, ‘has_eal’ => ‘Boolean’, ‘support’ => ‘String’, ‘has_cin’ => ‘Boolean’, ‘has_lac’ => ‘Boolean’ ]; protected $fillable = [ ‘first_name’, ‘last_name’, ‘has_pp’, ‘has_eal’, ‘support’, ‘has_cin’, ‘has_lac’ ]; public function company(){ ..

Read more

I was using "jenssegers/mongodb": "2.1" and switched to "jenssegers/mongodb": "3.0.x" while upgrading from Laravel5.0 to Laravel 5.1 with php 5.6.x I modified my codes for the upgraded version, but I’m no longer able to get the results count as used to before with this code: $results = DB::connection($connection) ->collection("listing") ->timeout(-1) ->raw(function ($collection) use ($filters, $cols) ..

Read more

I am new to mongodb and using the aggregate function to fetch some records Query I used is: $records = $this->raw()->aggregate([ [‘$match’ => ["ts" => [‘$gte’=> $startTime,’$lt’=> $endTime]]], [‘$group’ => ["_id" =>["config" => ‘$conf’, "status" => ‘$s’ ], "count" =>[‘$sum’ =>1]], "ts" => [ ‘$dateToString’ => [ ‘format’ => ‘%Y-%m-%d’, ‘date’ => $startTime, ‘timezone’ => ..

Read more

It must be a very stupid question but I am unable to fetch a date key in the mongo aggregate function in laravel framework I used this query to fetch the records but I am not getting how to store the "ts" key in the records too. $records = $this->raw()->aggregate([ [‘$match’ => ["ts" => [‘$gte’=> ..

Read more

I’m trying to crear a seeder on laravel 6 using mongodb this is database.php use IlluminateSupportStr; return [ ‘default’ => env(‘DB_CONNECTION’), ‘connections’ => [ ‘mongodb’ => [ ‘driver’ => ‘mongodb’, ‘host’ => env(‘DB_HOST’), ‘port’ => env(‘DB_PORT’), ‘database’ => env(‘DB_DATABASE’), ‘username’ => env(‘DB_USERNAME’), ‘password’ => env(‘DB_PASSWORD’), ‘options’ => [ ‘database’ => ‘mydb’ ] ], ], and ..

Read more

hello so this is my first laravel project and i’m lost.. i have a mongodb database that has a users collection and a posts collection this is my Post model: <?php namespace AppModels; use IlluminateDatabaseEloquentFactoriesHasFactory; use IlluminateDatabaseEloquentModel; use JenssegersMongodbEloquentSoftDeletes; /** * @method static create(array $array) * @method static firstWhere(string $string, int $id) */ class Post ..

Read more

I tried to create a mongodb logging channel ‘mongo’ => [ ‘driver’ => ‘monolog’, ‘handler’ => MonologHandlerMongoDBHandler::class, ‘formatter’ => MonologFormatterMongoDBFormatter::class, ‘handler_with’ => [ ‘mongo’ => new MongoDBClient("mongodb://localhost:27017"), ‘database’ => ‘testdb’, ‘collection’ => ‘testcoll’ ] ], However, im getting error: IlluminateContractsContainerBindingResolutionException(code: 0): Unresolvable dependency resolving [Parameter #0 [ <required> $mongodb ]] in class MonologHandlerMongoDBHandler The error ..

Read more

this code working fine when i not change j.acc_no value, If we change j.acc_no value it does not update the document. any one suggest any idea to fix this $updateData = [ ‘bank.$[i].details.$[j].acc_name’ => ‘raja K’, ‘bank.$[i].details.$[j].acc_no’ => ‘35252555’, ‘bank.$[i].details.$[j].min_deposit’ => ‘10000’, ‘bank.$[i].details.$[j].max_deposit’ => ‘1000000’, ‘bank.$[i].details.$[j].status’ => 1, ]; $filters = [ [‘i.bankname_slug’ => [‘$eq’ ..

Read more

I have an array(or collection) like this for my notifications. Each notification has an array field for all users who has seen the notification. array:2 [ 0 => array:8 [ "_id" => "604485ddf92e0000050079c6" "title" => "Notification title" "message" => "Notification message" "type" => "success" "expire_date" => "2021-05-09T19:30:00.000000Z" "read_by_users" => array:2 [ 0 => array:2 [ ..

Read more

I’m trying to setup MongoDB in a Laravel Jetstream + Sail. What I’m doing is trying to install the following packages: mongodb/mongodb jenssegers/mongodb but I get the following errors : Problem 1 – jenssegers/mongodb[v3.8.0, …, v3.8.2] require mongodb/mongodb ^1.6 -> satisfiable by mongodb/mongodb[1.6.0, …, 1.9.x-dev (alias of dev-master)]. – mongodb/mongodb 1.9.x-dev is an alias of ..

Read more

I am running following query in mongodb collection and I am using this package https://github.com/jenssegers/laravel-mongodb to communicate with mongodb in laravel. $ibQuery = $this->model->project([‘message_count’ => [ ‘$size’ => [ ‘$ifNull’ => [‘$messages’, []] ] ] ]) ->get(); return $ibQuery; and I am getting this error. exception: "MongoDBDriverExceptionCommandException" file: "/opt/lampp/htdocs/my-project/vendor/mongodb/mongodb/src/Operation/Find.php" line: 337 message: "Unsupported projection option: ..

Read more

i have data in mongodb it is a road object that has a property and an array of points that it consists of: my model in laravel <?php namespace AppModels; use AppTraitsUuids; use GraphQLTypeDefinitionType; use RebingGraphQLSupportFacadesGraphQL; use JenssegersMongodbEloquentModel as Eloquent; class Road extends Eloquent { //use HasFactory; use Uuids; protected $connection = ‘mongodb’; protected $collection ..

Read more

I get wrong date from MongoDB using Eloquent in Laravel. My record in database looks like this "created_at" : ISODate("2020-11-17T15:30:42.131+01:00") Code to get records from MongoDB $taskObj = TaskComments::where(‘task_id’, $task_id)->get()->toArray(); Result date for created_at is 1970-01-25 20:31:23 which is wrong, I would like to get in this format 2020-11-17 15:30:42 I would like to create ..

Read more