Using NestJS to populate data will only populate the first element

I have a Mongoose schema in NestJS structured like this:


...
@Prop()
  casinoAmount: number;

  @Prop()
  gameHyperLink: string;

  @Prop()
  casinoHyperLink: string;

  @Prop({ type: Types.ObjectId, ref: 'Game' })
  games: Game[];
}

I'm trying to create a query that performs a full "left join", meaning it selects each Provider with all elements from the corresponding games.

If I run a regular query (without using populate), it will simply return all the ObjectID's.

    const providers = await this.providerRepository
      .find({})
      .skip(offset)
      .limit(limit)
      .exec();

https://i.stack.imgur.com/OKMjH.png

However, when I try to populate the data like this

    
const providers = await this.providerRepository
      .find({})
      .populate('games')
      .skip(offset)
      .limit(limit)
      .exec();

https://i.stack.imgur.com/CR3SD.png

The issue is that it only returns a single game object instead of a list containing all the objects. Can anyone explain why this is happening?

Answer №1

It's important to avoid using exec() alongside await when making queries. Instead, you can incorporate skip() and limit() within the populate function like the example below:

await this.providerRepository.find({}).populate({
    path:'games',
    options: {
        limit: limit,
        skip: skip
    })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtain the date in the following format: 2016-01-01T00:00:00.000-00:00

Can someone help me convert this date to the correct format for the mercadolibre api? I need it to be like this: 2016-01-01T00:00:00.000-00:00 However, when I try with the following code: var date_from = new Date(); date_from.setDate(date_from.getDa ...

Node Webkit: No visible content?

Recently, I decided to explore Node-Webkit and encountered an issue. Despite coding the script below, nothing seems to appear on the screen and the file I intended to create remains missing. Even after installing npm for fs and os modules, I still face no ...

Setting up a connection to MongoDB on a local network using express and mongoose

As I set up a server with express and mongoose, my goal is to make it accessible on other devices within my local network. To achieve this, I configured the bind_ip variable to 0.0.0.0 in the Mongodb configuration file. const connection = mongoose .co ...

Angular application triggering multiple subscribe method calls upon a link click event

Here is the code for my navbar component: <li *ngFor="let item of menu"> <a *ngSwitchCase="'link'" routerLinkActive="active" [routerLink]="item.routerLink" (click)="Navigation(item.title)&q ...

You are not able to alter headers once they have been sent to the client according to the new NodeError

I'm attempting to create a reload animation as middleware between the request and response. When the user waits for a response, a reload waiting animation will run in the browser (I am using Node.js & Express, and EJS templating engine). Here is the ...

What is the best way to manage Page Refresh using Angular.js?

I recently followed the tutorial at http://scotch.io/bar-talk/setting-up-a-mean-stack-single-page-application This guide went over controllers and services using angular.js for a single-page application. However, when I try to directly access /pageName o ...

What steps can be taken to turn off the ETag feature in npm's express during configuration?

I am a beginner in using nodejs and npm. I have been given the task of disabling Etag generation in the configuration level of npm express. The answer I found is to use app.set('etag', false); // turn off but I am looking for similar solutions on ...

Having trouble retrieving req.session variables in Express/NodeJS?

I have come across various versions of this particular question, however, none of them seem to address my issue directly. My current objective is to establish a Node.js server using Express. Below is my existing server configuration: var express = require ...

Encountering a "Cannot GET /" error message

We are currently utilizing Next.js/React.js for our front-end, along with a server.js file that facilitates image uploads to the public/images/uploads directory. However, we are encountering an error message stating Cannot GET / when attempting to run the ...

"Discovering the method to showcase a list of camera roll image file names in a React Native

When attempting to display a list of images from the user's camera roll, I utilized expo-media-library to fetch assets using MediaLibrary.getAssetsAsync(). Initially, I aimed to showcase a list of filenames as the datasource for the images. Below is m ...

What are the steps to correct a missing property in an established type?

Currently, I am in the process of converting an existing Node.js + express application from plain JS to TypeScript. Although I understand why I am encountering this error, I am unsure about the correct approach to resolve it. The type "Request" is coming f ...

What is the best way to link PostgreSQL with a React frontend using restify?

Login.js This is a Reactjs login page that requires moving to the next page after successful authentication. The database being used is postgreSQL with a table named 'user' for storing usernames and passwords. The development requirements inc ...

Setting up Firebase App Check in an Angular projectWould you like to know

I have a question about initializing Firebase app check with Angular. I am currently using AngularFire, but I'm not sure how to initialize Firebase app check before using any services. The documentation provides the following initialization code to b ...

After upgrading to Angular 15, the Router getCurrentNavigation function consistently returns null

Since upgrading to angular 15, I've encountered a problem where the this.router.getCurrentNavigation() method is returning null when trying to access a state property passed to the router. This state property was initially set using router.navigate in ...

Ensuring consistency between TypeScript .d.ts and .js files

When working with these definitions: https://github.com/borisyankov/DefinitelyTyped If I am using angularJS 1.3.14, how can I be certain that there is a correct definition for that specific version of Angular? How can I ensure that the DefinitelyTyped *. ...

Guide on interacting with ExpressJS REST API endpoints using C# code

After successfully setting up a backend server with multiple endpoints using NodeJS and the ExpressJS framework, I connected these REST Api Endpoints to a Mongodb Database. However, for a specific project requirement, I needed to write some code in C# tha ...

Axios - Error: Promise Rejected - The request was unsuccessful with a 500 status code

The Axios post request in my code for adding new articles is not going through, and I am encountering an error: Failed to load resource: the server responded with a status of 500 (Internal Server Error) createError.js:17 Uncaught (in promise) Error: Requ ...

Tips for customizing the appearance of a label when a MUI Radio Button is selected

Hello everyone, I am attempting to customize the label text color of a radio button to turn blue when selected. https://i.stack.imgur.com/btSc2.jpg HERE IS THE CODE FOR MY MUI BUTTON SO FAR import * as React from "react"; import Radio from &quo ...

Accessing React.FC in Another File with TypeScript - A Step-by-Step Guide

code - const Exne: React.FC <IProps> = ({x}) => { console.log('input', x); const [getx, assignx] = useState(x); console.log(getx, assignx); return(getx) }; Could you please provide instructions on how to acc ...

How Angular services transmit information to components

I have implemented a search field within my top-bar component and I am facing an issue in passing the input value of that search field to another component. Design Search service Top bar component Result component Operation Top bar component receives th ...