Category : mongodb

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

im recently changed my database from MySQL to mongodb I’m using jesenger in Laravel I’m trying to use this query for my many to many relations but it wont work(using jenssegers/laravel) $query->whereHas(‘opcos’,function ($query) use($useropco){ $query->whereIn(‘opco_id’,[1,2,3])->get(); }); how can use this kind of search in mongo database? my models: asset: public function opcos(){ return $this->belongsToMany(Opco::class); } ..

Read more

i’am facing a probleme while trying to connect to my mongoDB with robo t3 My docker container connfiguration : todo_mongodb: container_name: mongodb image: mongo:latest ports: – "27017:27017" environment: – MONGO_INITDB_ROOT_USERNAME=admin – MONGO_INITDB_ROOT_PASSWORD=admin – MONGO_INITDB_DATABASE=admin volumes: – "./mongo/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d" Docker ps command show’s : i’am able to access mongodb shell and login as admin using winpty docker ..

Read more

How do I arrange the Selected Fields in MongoDB? I have here list of fields Inside an array, $fields_list = [ ‘first_name’, ‘middle_name’, ‘last_name’, ‘job_title’, ‘phone’, ’email’, ‘functional_area’ ]; Then I have this query $result = $this->mongodb->collection($table_name) ->where(self::COMPANYNAME,$company_name) ->get($fields_list); $result = $this->mongodb->collection($table_name) ->select(‘first_name’,’middle_name’,’last_name’,’job_title’,’phone’,’email’,’functional_area’) ->where(self::COMPANYNAME,$company_name) ->get(); Both of these queries does not arrange the result output, ..

Read more

Laravel version : 7 I try to install "composer require jenssegers/mongodb" but facing problem as below. I gave no clue what it’s mean Problem 1 – jenssegers/mongodb[v3.8.0, …, v3.8.1] require illuminate/support ^8.0 -> found illuminate/support[v8.0.0, …, 8.x-dev] but it conflicts with another require. – Root composer.json requires jenssegers/mongodb ^3.8 -> satisfiable by jenssegers/mongodb[v3.8.0, v3.8.1]. Source: ..

Read more

enter image description here how to solve this error folks? i’m trying to get data from management and managmentType Revers: query { mangmenttypes { name Managment{ name } } } and this error showed up and always nested queries show null for the embeddedthe query type in graphql schema query Models Managment and ManagmentType Models ..

Read more

In laravel i have one function called delete($id) from this function i m getting particular field id, but in find() this id is not getting matched with mongodb database, this query is not returning anything, I want this $id value should get matched with mongodb ObjectId. $result = $collection->find([‘_id’=>$id]); Sourc..

Read more

here is the Mysql Query: SELECT name, sum(case when reason = ‘fb’ then score else 0 end) as fb, sum(case when reason = ’email’ then score else 0 end) as email from multi_group group by name I am trying to convert this query in MongoDb: $query = Model::raw(function($collection) { return $collection->aggregate([ [ ‘$group’ => [ ..

Read more

I have the following collection: [ { "_id":"5fabdd45bf510000d7001430", "application_id":27, "employ_id":1, "reason":"email", "score":1800 }, { "_id":"5fabdd50bf510000d7001431", "application_id":28, "employ_id":1, "reason":"email", "score":1800 }, { "_id":"5fabdd5dbf510000d7001432", "application_id":28, "employ_id":2, "reason":"email", "score":1800 }, { "_id":"5fabdd68bf510000d7001433", "application_id":27, "employ_id":2, "reason":"email", "score":1800 }, { "_id":"5fabdd79bf510000d7001434", "application_id":27, "employ_id":2, "reason":"facebook", "score":1000 }, { "_id":"5fabdd84bf510000d7001435", "application_id":27, "employ_id":1, "reason":"facebook", "score":1000 } ] I want to calculate the score ..

Read more

I have an application with laravel and mongodb. With elequent iam trying to append a new value to an array stored in a field. So this is an example of a document. Iam trying to append a new value to the projects field. { "_id":{ "$oid":"5f80513714450000a6007c90" }, "organization_id":"5f80304214450000a6007c81", "user_id":"5f80513714450000a6007c8f", "status":true, "role_id":"5c148783fe412ba8333074ec", "company_id":"5f80511f14450000a6007c8e", "updated_at":{ "$date":"2020-11-09T18:42:03.000Z" }, ..

Read more

I have a project that implements an event source using https://github.com/spatie/laravel-event-sourcing. And now I want to use MongoDB to store the event store, using https://github.com/jenssegers/laravel-mongodb. But I get stuck to implement both. Both packages required to extends their own class. This is my custom model for the event source. <?php namespace AppModelsMongoDB; use SpatieEventSourcingStoredEventsModelsEloquentStoredEvent; use ..

Read more

I’m using Lumen as a framework for a REST API and have installed Jenssegers’ MongoDB driver to work with Eloquent. So far so good. I have been successful in creating pseudo-schema migrations and a seeder for a ‘users’ table using a factory class that contains faker information. User::factory() ->time(50) ->create(); Now I want to add ..

Read more

I’m using laravel 6.xx with jenssegers/laravel-mongodb. Previously I was using MySQL and the query working fine without any issues. When I use laravel MongoDB the following query returning empty. $user_id = Auth::id(); $data = Post::active() ->wheredoesntHave(‘PostBlock’, function($qry) use ($user_id) { $qry->where(‘user_id’, $user_id); }) ->whereIn(‘Post_permission’, [‘public’, ‘request’]) ->orWhere(function($query) use ($user_id) { $query->where(‘Post_permission’, ‘private’) ->whereHas(‘PostAccess’, function($qry) use ..

Read more

When I run this command from my local machine: docker-compose exec php php ../artisan migrate I receive the following error message: In functions.php line 431: No suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve ‘db’] The environment code structure on the local machine looks like this: . +– _images | +– _php | +– +– ..

Read more