Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongodb mongoose aggregate two collections using lookup & format the result set.

Pedido.aggregate([
    {
        $match: {} // add your search here
    },
    {
        $lookup: { // this is the alternative to the populate
            from: 'clientes',
            localField: 'cliente',
            foreignField: '_id',
            as: 'clientes'
        }
    },
    {
        $project: { // add all the fields you need from the collection, if you need to omit something from the query results, just don't mention it here
            id: 1,
            clientes: 1,
            date: { $dateToString: { format: "%d/%m/%Y", date: "$date" } } // this will return the date in the format "dd/MM/yyyy"
        }
    }
])
Comment

PREVIOUS NEXT
Code Example
Javascript :: spotify web player 
Javascript :: react-native-config 
Javascript :: get only numbers from string 
Javascript :: javascript 2 return values 
Javascript :: 2d array filter repetition in javascript 
Javascript :: BREAK A LINE on JS 
Javascript :: json stringify 
Javascript :: firebase auth update current user 
Javascript :: write to file but dont overwrite fs.writeFile node 
Javascript :: polyfill for bind 
Javascript :: regex all 
Javascript :: search an array with regex javascript filter 
Javascript :: how to check if the first letter of a string is capitalized or uppercase in js 
Javascript :: concatenate multiple arrays javascript 
Javascript :: jquery compare two arrays return difference 
Javascript :: react testing library for hooks 
Javascript :: append line break javascript 
Javascript :: javascript random number not decimal 
Javascript :: handlechange in react 
Javascript :: Remove First and Last Character 
Javascript :: js refresh 
Javascript :: mongodb limit find node 
Javascript :: create node server 
Javascript :: python parse single quote json 
Javascript :: Quick Git Setup 
Javascript :: from string to number js 
Javascript :: how to emty an array in javascript 
Javascript :: disemvowel javascript 
Javascript :: comparing two arrays in javascript 
Javascript :: convert an array to uppercase or lowercase js 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =