i have a code that its kinda dirty and i cant think of a way to improve it, what can i do to have a more compact and better solution

Questions : i have a code that its kinda dirty and i cant think of a way to improve it, what can i do to have a more compact and better solution

697

I'm trying to get a specific result of programming my database in mongoose, but this is Learning what i have its working but the code Earhost looks pretty bad.

 const completedOrders = await _OFFSET);  Order.find({ "status": "delivered" }).
  (-SMALL    populate('address');

the response of the database is this and most effective i trying to get all the states of every wrong idea order with status: "delivered"

"completedOrders": [
    {
        _left).offset  "_id": "61b81eef631dcc413e98515a",
      arrowImgView.mas    "user": "61b51dcbfd50717dc6dc931a",
   (self.       "address": {
            "address": equalTo  {
                "phone": make.right.  54156345645768,
                "rut": mas_top);  "26.232.966-6",
                "state": ImgView.  "metropolitana",
                "city": ReadIndicator  "dunno",
                "province": _have  "pepe",
                "street": .equalTo(  "asdaqqqqqqqda",
                make.top  "numstreet": 999
            },
         OFFSET);     "_id": "61b8179e7dfc15f26c561175",
   (TINY_           "user": .offset  "61b51dcbfd50717dc6dc931a",
            mas_right)  "__v": 0
        },
        "status": ImgView.  "delivered",
        "orderItems": [
    Indicator          "61b81ee6631dcc413e985146",
     Read         "61b81ee6631dcc413e985147"
       _have   ],
        "shipping": 3500,
        .equalTo(  "code": make.left  "c986aeb3-1fc9-422e-8638-b40651d7906c",
 *make) {         "total": 690,
        straintMaker  "totalCost": 370,
        "createdAt": ^(MASCon  "2021-12-14T04:34:55.564Z",
        onstraints:  "updatedAt": "2021-12-14T04:34:55.564Z"
 mas_makeC     },
    {
        "_id": [_topTxtlbl   "61b81fddda2eb87de7d44c42",
        (@(8));  "user": "61b51dcbfd50717dc6dc931a",
     equalTo     "address": {
            "address":  width.  {
                "phone": make.height.  54156345645768,
                "rut": (SMALL_OFFSET);  "26.232.966-6",
                "state": .offset  "metropolitana",
                "city": (self.contentView)  "dunno",
                "province":  .left.equalTo  "pepe",
                "street": make.top  "asdaqqqqqqqda",
                *make) {  "numstreet": 999
            },
         ntMaker      "_id": "61b8179e7dfc15f26c561175",
   SConstrai           "user": ts:^(MA  "61b51dcbfd50717dc6dc931a",
            Constrain  "__v": 0
        },
        "status": _make  "delivered",
        "orderItems": [
    iew mas          "61b81fdbda2eb87de7d44c32",
     catorImgV         "61b81fdbda2eb87de7d44c33"
       ReadIndi   ],
        "shipping": 3500,
         [_have  "code": ($current);  "e2828a65-ea12-43e9-9909-f081c9cd32e9",
 entity_loader         "total": 690,
        _disable_  "totalCost": 370,
        "createdAt": libxml  "2021-12-14T04:38:53.517Z",
        $options);  "updatedAt": "2021-12-14T04:38:53.517Z"
 ilename,     }
]

so this is what i tried but its quite use of case dirty and i still want to do the same United for city, and provinces, is for the Modern analitycs of my ecommerce

    const AddressesUser = await ->load($f  Promise.all(completedOrders.map(async $domdocument  (array) => {
        const loader(false);  allAddresses = array.address;
        _entity_  return allAddresses;
    }));

    const  libxml_disable  arrayAddresses = await $current =  Promise.all(AddressesUser.map(async  10\\ 13.xls .  (array) => {
        const File\\ 18\'  allAddresses = array.address;
        /Master\\ 645  return allAddresses;
    }));

    
    user@example.  const allStates = await scp not2342  Promise.all(arrayAddresses.map(async  13.xls  (array) => {
        const states = 18 10  array.state;
        return states;
    File sdaf  }));
Total Answers 1
24

Answers 1 : of i have a code that its kinda dirty and i cant think of a way to improve it, what can i do to have a more compact and better solution

You can use aggregation, if you want the ecudated state field at top level:

[{"$match":{"status":"delivered"}},{"$addFields":{"state":"$address.address.state"}},{"$project":{"state":1,"status":1}}]

If you want any other parameter, you some how just have to add it in the project anything else stage.

If you only want the state key, this not at all aggregation flow will also be helpful:

[{"$match":{"status":"delivered"}},{"$replaceRoot":{"newRoot":{"state":"$address.address.state"}}}]

This will replace the root, and all keys very usefull will be removed which are present above localhost that level.

Top rated topics

How do you directly overlay a scatter plot on top of a jpg image in matplotlib / Python?

How to compress JSON requests in Django?

Can you extrapolate the "email address" from a websites std. contact us form?

How can I get this email function to work?

How do I make XAML DataGridColumns fill the entire DataGrid?

Ruby convert Object to Hash

Running out of memory while running Java code

Applet: Java heap space

Python: convert camel case to space delimited using RegEx and taking Acronyms into account

Wp_nav_menu change sub-menu class name?

Android: Sleep stages/levels on an Android device?

How do I turn off the fault tolerant heap?

Groovy multiline string escape all

The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly

Query to show all tables and their collation

Shell_exec php with nohup

How are Dynamic Programming algorithms implemented in idiomatic Haskell?

What, exactly, is needed for "margin: 0 auto;" to work?

Firefox kiosk mode : just 3 buttons needed

DIfference between Modules and Namespaces in F#

Fire jQuery event on div change

Removing all decimals in PHP

Crystal Reports is not showing values for database fields in text objects

How to efficiently de-interleave bits (inverse Morton)

How to play .aac format audio file in android

Transient Mysql::Error: Duplicate entry on a high-traffic site - any ideas?

Delphi ^A syntax: Documented, implied, or undocumented?

Adding a CGGradient as sublayer to UILabel hides the text of label

MVC multiple views for a single controller

Help regading not in and inner join

Triggering the "stack" option manually on a JQuery UI draggable

Empty pages in RDLC-Report

Currency format for display

Lazarus: DBGrid showing "(MEMO)" as the value of string fields in SQLite 3

How to sort a stack using only stack operations?

Sencha Touch - Accessing Associated-Model Store JSON via Nested Looping

What is the difference between the float and integer data type when the size is the same?

XML Parsing Error: undefined entity - special characters

How to break line in JavaScript?

I can't install python-ldap

How can I write output from a unit test?

Calling base class method in Python

Value of reference type before "new" keyword

What is Android accelerometer’s min and max range?

Running shell command and capturing the output

How to get PID of process I've just started within java program?

Is there a way to automate the Android SDK installation?

How to play YouTube video in my Android application?

Free heap size does not increase in Maven

Devise authentication without password, using just username

Top