social media app

Closed Posted 2 weeks ago Paid on delivery
Closed

Project Title: MongoDB Aggregation Performance Optimization

Project Description:

We are experiencing significant delays with a MongoDB aggregation pipeline in our application. The specific controller takes about 36 seconds to complete when a user has a large amount of chat data in the database. We need a MongoDB expert to review and optimize the aggregation pipeline for improved performance.

Details:

Our application is built using Node.js with Mongoose as the ODM for MongoDB. The current issue arises when retrieving a user's chat list. The aggregation pipeline fetches chat messages for a given user, including related user information and performs various operations like sorting, grouping, and filtering based on certain criteria.

Current Function:

Here’s the function that handles the retrieval of user chats:

javascript

Copy code

const userChatList = async (userId, page, language) => {

try {

const user = await [login to view URL](userId);

if (!user) {

throw 'User not found';

}

const pageNb = parseInt(page) || 1;

let limit = 10;

if (['affiliate', 'admin'].includes([login to view URL])) {

limit = 20;

}

if (pageNb < 1) {

throw 'Invalid page';

}

const startIndex = (pageNb - 1) * limit;

let matchLanguage = {};

if (language) {

matchLanguage = {

$or: [

{ '[login to view URL]': language },

{ '[login to view URL]': language },

],

};

}

const aggregatedChats = await [login to view URL]([

{

$match: {

$or: [{ fromUser: userId }, { toUser: userId }],

},

},

{

$lookup: {

from: 'users',

localField: 'fromUser',

foreignField: '_id',

as: 'fromUserDetails',

},

},

{

$lookup: {

from: 'users',

localField: 'toUser',

foreignField: '_id',

as: 'toUserDetails',

},

},

{

$unwind: '$fromUserDetails',

},

{

$unwind: '$toUserDetails',

},

{

$match: matchLanguage,

},

{

$sort: { createdAt: -1 },

},

{

$group: {

_id: {

$cond: [{ $eq: ['$fromUser', userId] }, '$toUser', '$fromUser'],

},

lastMessage: { $first: '$$ROOT' },

},

},

{

$sort: { '[login to view URL]': -1 },

},

{

$skip: startIndex,

},

{

$limit: limit,

},

]);

// Further processing and emitting results via [login to view URL]

} catch (error) {

[login to view URL](error);

throw error;

}

};

Performance Results:

Total Time: 36.389s

Chat Aggregation: 35.670s

chats model:

`const mongoose = require('mongoose');

const chatSchema = new [login to view URL](

{

fromUser: {

type: [login to view URL],

ref: 'User',

},

toUser: {

type: [login to view URL],

ref: 'User',

},

type: {

type: String,

enum: ['text', 'audio', 'image', 'video'],

},

text: {

type: String,

},

voice: {

type: String,

},

image: {

type: String,

},

video: {

video: { type: String },

thumbnail: { type: String },

},

audio: {

type: String,

},

wasLocked: {

type: Boolean,

default: false,

},

isLocked: {

type: Boolean,

default: false,

},

diamonds: {

type: Number,

},

isRead: {

type: Boolean,

default: false,

},

isSubscribed: {

type: Boolean,

default: false,

},

},

{

timestamps: true,

}

);

// Compound index for fromUser and toUser

[login to view URL]({ fromUser: 1, toUser: 1 });

// Index for createdAt for sorting

[login to view URL]({ createdAt: -1 });

[login to view URL]({ toUser: 1, createdAt: -1 });

[login to view URL] = [login to view URL]('Chat', chatSchema);

`

Requirements:

Review and Optimize Aggregation Pipeline:

We need you to review the existing aggregation pipeline and suggest improvements to reduce the execution time.

Indexing:

Assess the current index setup and suggest or implement changes to optimize the aggregation.

Profile Database:

Use MongoDB performance tools to identify potential bottlenecks and propose or implement solutions.

Document Changes:

Document any changes you make and provide recommendations for future improvements.

Skills Required:

MongoDB

Mongoose

Node.js

Database Optimization

Performance Profiling

Please provide an estimate for the expected budget and timeline for this task. We are seeking to resolve this issue as soon as possible. Please DO NOT waste our time if you are not totally skilled and if you a chatGPT only user.

JavaScript MongoDB Node.js Database Programming Performance Tuning

Project ID: #38068859

About the project

49 proposals Remote project Active last week

49 freelancers are bidding on average $21/hour for this job

AwaisChaudhry

Hello Good morning , I just finished reading the job description . I see you are looking for someone experienced in developing products using JavaScript, Database Programming, Performance Tuning, Node.js and MongoDB. T More

$25 USD / hour
(88 Reviews)
8.4
ashok1984

Hello Abdelmalek A., After carefully reviewing your project description "social media app", we believe that our team is exceptionally suited for this job. We have very good expertise in your mentioned skills i.e. Jav More

$24 USD / hour
(54 Reviews)
8.0
tangramua

Dear Abdelmalek A.,   We carefully studied the description of your project and we can confirm that we understand your needs and are also interested in your project. Our team has the necessary resources to start your pr More

$25 USD / hour
(64 Reviews)
7.4
malkesh3m

⭐ Hi, My availability is immediate. I read your project post on NodeJS/React Developer. We have extensive knowledge in MERN Stack (MongoDB/MySQL, Express JS, React, and NodeJS), as well as RESTful API integration. We More

$16 USD / hour
(23 Reviews)
5.2
LiveExperts

Hi there, I have read your project description and i'm confident i can do this project for you perfectly.I still have a few questions. please leave a message on my chat so we can discuss the budget and deadline of the More

$50 USD / hour
(6 Reviews)
5.0
yasirk1979

Greetings Abdelmalek, I want to team up with you to tackle this challenging project I am a specialist in MongoDB optimization I will propose a set of optimization strategies, which may include indexing improvements, qu More

$22 USD / hour
(3 Reviews)
5.5
pksaini1990

HI, With over 12 years of experience, a project completion rate of 96%, and rankings on the top 10% of Freelancer profiles, I believe that I am the right developer for your MongoDB performance optimization project. A More

$20 USD / hour
(12 Reviews)
5.4
ajeshjanardanan

Hi Abdelmalek A., How are you doing? As a professional developer with expertise in Performance Tuning, Node.js, Database Programming, JavaScript and MongoDB, I eagerly anticipate the opportunity to complete this projec More

$50 USD / hour
(5 Reviews)
4.0
caroldata

Hello there, I'm senior Fullstack Developer with lots of experiences in all main technologies, You can count on me to deliver perfect work My main tech is MERN stack and specially React is my major I used Nodejs and More

$20 USD / hour
(5 Reviews)
5.3
sakshitiwari2323

Hello, I am writing to express my interest in your project, "MongoDB Aggregation Performance Optimization." I understand the challenges you are facing with the MongoDB aggregation pipeline, particularly the extended du More

$20 USD / hour
(4 Reviews)
4.0
ritikgarg55

Hello, my name is Ritik Garg and I am a Full-Stack/Backend Developer with 5 years of experience working with Python, Django, Restful APIs, Data Mining, Flask, Scrapy, Selenium, Flask, Node JS, Angular, React, AWS, DevO More

$20 USD / hour
(10 Reviews)
3.2
amineElANBARI

Hello I've over 3 years of experience in MERN stack included MongoDB, I have the suffisant experience to optimize the process of fetching chat user data I'm sure that I will fix all problems that you're facing as soo More

$20 USD / hour
(4 Reviews)
3.0
AdhamSoft

السلام عليكم ورحمه الله وبركاته اخي الكريم انا لدي خبره كبيره في تصميم المواقع كما انا لدي خبره في تصميم تطبيقات الموبايل ولدي فريق عمل متكامل في حال احتاجنا اي شيء اضافي كما يمكننا ايضا الاستفاده من خبرات المصممين ال More

$20 USD / hour
(1 Review)
2.6
lovelyfaheem

Hi Abdelmalek! How are you doing? I am experienced in MongoDB, Mongoose, Node.js, and database optimization with performance profiling. I have successfully completed similar projects involving firmware updates and data More

$15 USD / hour
(5 Reviews)
2.9
AgustinMaidana

Hello Abdelmalek A. I have read your project description carefully and it sounds very interesting to me cuz I am full stack developer. I have a that has a strong experience for Database Programming, JavaScript, Node.j More

$50 USD / hour
(1 Review)
1.8
yolosingh564

Hello, I've reviewed your requirement for optimizing the MongoDB aggregation pipeline that's currently causing delays in your application, especially concerning chat data retrieval. From your description, it's clear t More

$15 USD / hour
(1 Review)
1.6
luis00701

Hello Abdelmalek A., This is Enrique. Hope you are doing well. I'm very interested in your project since I'm very confident in Performance Tuning, Node.js, Database Programming, MongoDB and JavaScript. As a experience More

$20 USD / hour
(0 Reviews)
0.0
toobagala7

As a seasoned Node.js developer, I'm already familiar with the technology stack you have in place and have extensive experience working with MongoDB, especially on improving query performance. With your social media ap More

$15 USD / hour
(0 Reviews)
0.0
ichaina

Hi Abdelmalek, I'm excited about this job opportunity since my primary skills are great for this job requirement. I have over 6 years of experience on JavaScript, Node.js, Database Programming, MongoDB, Performance T More

$20 USD / hour
(0 Reviews)
0.0
klevisolutions

Hello, I'm a MongoDB Expert. I don't use the ChatGPT. I have rich experience about MongoDB aggregation and while work as a backend developer, to improve the code quality and optimize of backend development. If you hir More

$20 USD / hour
(0 Reviews)
0.0