Snippets Collections
db.timetable.updateMany(
   {},
   { $rename: { 'Train No': 'trainNo', 'Train Name': 'trainName', 'SEQ':'seq', 'Station Code':'stationCode', 'Station Name': 'stationName', 'Arrival time':'arrivalTime', 'Departure Time':'departureTime', 'Distance':'distance', 'Source Station':'sourceStation','Source Station Name':'sourceStationName', 'Destination Station':'destinationStation','Destination Station Name':'destinationStationName'  } }
)
//Applies an accumulator function over a sequence.

//public static TSource Aggregate<TSource>
//(this System.Collections.Generic.IEnumerable<TSource> source,
//Func<TSource,TSource,TSource> func);

string sentence = "the quick brown fox jumps over the lazy dog";

// Split the string into individual words.
string[] words = sentence.Split(' ');

// Prepend each word to the beginning of the
// new sentence to reverse the word order.
string reversed = words.Aggregate((workingSentence, next) =>
                                      next + " " + workingSentence);

Console.WriteLine(reversed);

// This code produces the following output:
//
// dog lazy the over jumps fox brown quick the




//Applies an accumulator function over a sequence. The specified seed value is used as the //initial accumulator value.

//public static TAccumulate Aggregate<TSource,TAccumulate> (this //System.Collections.Generic.IEnumerable<TSource> source, TAccumulate seed, //Func<TAccumulate,TSource,TAccumulate> func);


int[] ints = { 4, 8, 8, 3, 9, 0, 7, 8, 2 };

// Count the even numbers in the array, using a seed value of 0.
int numEven = ints.Aggregate(0, (total, next) =>
                                    next % 2 == 0 ? total + 1 : total);

Console.WriteLine("The number of even integers is: {0}", numEven);

// This code produces the following output:
//
// The number of even integers is: 6





//Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.

//public static TResult Aggregate<TSource,TAccumulate,TResult> (this System.Collections.Generic.IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate,TSource,TAccumulate> func, Func<TAccumulate,TResult> resultSelector);

string[] fruits = { "apple", "mango", "orange", "passionfruit", "grape" };

// Determine whether any string in the array is longer than "banana".
string longestName =
    fruits.Aggregate("banana",
                    (longest, next) =>
                        next.Length > longest.Length ? next : longest,
    // Return the final result as an upper case string.
                    fruit => fruit.ToUpper());

Console.WriteLine(
    "The fruit with the longest name is {0}.",
    longestName);

// This code produces the following output:
//
// The fruit with the longest name is PASSIONFRUIT.
  const filteredData = datas[0].PostOffice.map(({ Name, State }) => {
    return { Name, State };
  });
db.customers.find({}).forEach(function (ch){db.customers.updateMany({},{$set:{"contact":ch.contact.toString()}})});
const getSourcesData = asyncHandler(async (req, res) => {
  const { dealership } = req.user;
  const month = parseInt(req.params.month);
  const customerData = await Customer.aggregate()
    .match({ dealership })
    .facet({
      fbCount: [
        {
          $match: {
            sourceOfEnquiry: "Facebook",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "fbCount" },
      ],
      googleCount: [
        {
          $match: {
            sourceOfEnquiry: "Google",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },

        { $count: "googleCount" },
      ],
      cardekhoCount: [
        {
          $match: {
            sourceOfEnquiry: "Cardekho",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "cardekhoCount" },
      ],
      carwaleCount: [
        {
          $match: {
            sourceOfEnquiry: "Carwale",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "carwaleCount" },
      ],
      instagramCount: [
        {
          $match: {
            sourceOfEnquiry: "Instagram",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "instagramCount" },
      ],
      newspaperAdsCount: [
        {
          $match: {
            sourceOfEnquiry: "Newspaper Ads",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "newspaperAdsCount" },
      ],
      websiteCount: [
        {
          $match: {
            sourceOfEnquiry: "Website",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "websiteCount" },
      ],
      hoardingsCount: [
        {
          $match: {
            sourceOfEnquiry: "Hoardings",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "hoardingsCount" },
      ],
      telephonicCount: [
        {
          $match: {
            sourceOfEnquiry: "Telephonic",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "telephonicCount" },
      ],
      referralCount: [
        {
          $match: {
            sourceOfEnquiry: "Referral",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "referralCount" },
      ],
      workshopCount: [
        {
          $match: {
            sourceOfEnquiry: "Workshop",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "workshopCount" },
      ],
      bushfireCount: [
        {
          $match: {
            sourceOfEnquiry: "Bushfire",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "bushfireCount" },
      ],
      managementCount: [
        {
          $match: {
            sourceOfEnquiry: "Management",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "managementCount" },
      ],
      walkInCount: [
        {
          $match: {
            sourceOfEnquiry: "Walk-in",
            $expr: { $eq: [{ $month: "$createdAt" }, month] },
          },
        },
        { $count: "walkInCount" },
      ],
    });
  

  return res.status(200).json({
    success: true,
    tableData: customerData,
  });
});
{
  sourceOfEnquiry:'Telephonic',
    createdAt: {
        $gte: ISODate("2021-06-01T00:00:00.000Z"),
        $lte: ISODate("2021-06-30T00:00:00.000Z")
    }
}
db.users.updateMany(
  { __t: "SE" },
  {
    $set: {
      targets: [
        {
          modelName: "rapid",
          targetCount: 15,
          bookingCount: 0,
          deliveredCount: 0,
        },
        {
          modelName: "superb",
          targetCount: 10,
          bookingCount: 0,
          deliveredCount: 0,
        },
        {
          modelName: "kushaq",
          targetCount: 5,
          bookingCount: 0,
          deliveredCount: 0,
        },
        {
          modelName: "octavia",
          targetCount: 0,
          bookingCount: 0,
          deliveredCount: 0,
        },
      ],
    },
  }
);
const dateFilter = asyncHandler(async (req, res) => {
  const month = 7;
  const day = 13;
  const feedbacks = await Feedback.find({
    $expr: {
      $or: [
        {
          $and: [
            { $eq: [{ $month: "$birthday" }, month] },
            { $eq: [{ $dayOfMonth: "$birthday" }, day] },
          ],
        },
        {
          $and: [
            { $eq: [{ $month: "$anniversary" }, month] },
            { $eq: [{ $dayOfMonth: "$anniversary" }, day] },
          ],
        },
      ],
    },
  });
  res.send(feedbacks);
});
const dateFilter = asyncHandler(async (req, res) => {
  const month = 6;
  const day = 10;
  const feedbacks = await Feedback.find({
    $expr: {
      $or: [
        {
          $eq: [{ $month: "$birthday" }, month],
          $eq: [{ $dayOfMonth: "$birthday" }, day],
        },
        {
          $eq: [{ $month: "$anniversary" }, month],
          $eq: [{ $dayOfMonth: "$anniversary" }, day],
        },
      ],
    },
  });
  console.log({ feedbacks });
});
star

Mon Mar 06 2023 11:15:56 GMT+0000 (Coordinated Universal Time)

#nodejs #mongoose #mongodb #aggregate
star

Mon Apr 11 2022 16:59:32 GMT+0000 (Coordinated Universal Time) https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.aggregate?view=netframework-4.8#system-linq-enumerable-aggregate-3(system-collections-generic-ienumerable((-0))-1-system-func((-1-0-1))-system-func((-1-2)))

#linq #aggregate #seed #reverse #string
star

Fri Aug 20 2021 16:12:21 GMT+0000 (Coordinated Universal Time)

#nodejs #mongoose #mongodb #aggregate
star

Wed Jun 30 2021 11:07:26 GMT+0000 (Coordinated Universal Time)

#nodejs #mongoose #mongodb #aggregate
star

Wed Jun 30 2021 11:05:27 GMT+0000 (Coordinated Universal Time)

#nodejs #mongoose #mongodb #aggregate
star

Sat Jun 19 2021 09:25:48 GMT+0000 (Coordinated Universal Time)

#nodejs #mongoose #mongodb #aggregate
star

Fri Jun 11 2021 05:17:27 GMT+0000 (Coordinated Universal Time)

#nodejs #mongoose #mongodb #aggregate

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension