These are chat archives for Automattic/mongoose

21st
Jun 2016
Max
@maxfi
Jun 21 2016 07:47

Hey all. Anyone know how to achieve filtering an array (in an aggregation stage) using the $in query operator or something similar? This is what I'm trying to achieve:

  { 
    $project: {
      groupOneItems: {
        $filter: {
          input: '$lineItems',
          as: 'lineItem',
          cond: {
            '$$lineItem.productId': { $in: ['2000', '2200'] }
          }
        }
      },
      groupTwoItems: {
        $filter: {
          input: '$lineItems',
          as: 'lineItem',
          cond: {
            '$$lineItem.productId': { $in: ['3000', '3200'] }
          }
        }
      }
    }
  }

Any assistance would be greatly appreciated! Thanks!

Rishabh Saxena
@rishabh-saxena
Jun 21 2016 10:50
Can anybody provide me any reliable source where i can get information about how to use mongoose to connect with frontend using express.....
Alex Shpak
@ishikawayoshi
Jun 21 2016 10:53
@rishabh-saxena what problem you have?
Rishabh Saxena
@rishabh-saxena
Jun 21 2016 10:59
@ishikawayoshi i got various resources for connecting monk and express for mongodb database but am unable to find it for mongoose.It would be great help if you can provide some resource link.
Rishabh Saxena
@rishabh-saxena
Jun 21 2016 11:16
@ishikawayoshi they arent using express......
Mohamed Nasrullah
@nasr18
Jun 21 2016 11:18
search briantford.com
Rishabh Saxena
@rishabh-saxena
Jun 21 2016 11:21
@nasr18 the only last link that seemed to be useful wasnt working..... :/
Thanks @ishikawayoshi the link seems to be useful.....
Alex Shpak
@ishikawayoshi
Jun 21 2016 11:23
@rishabh-saxena it was second link in google search results ;)
Rishabh Saxena
@rishabh-saxena
Jun 21 2016 11:26
@ishikawayoshi i know...... :)
Mohamed Nasrullah
@nasr18
Jun 21 2016 11:28
@rishabh-saxena u got??
Rishabh Saxena
@rishabh-saxena
Jun 21 2016 11:29
@nasr18 the last link wasnt working.....
Mohamed Nasrullah
@nasr18
Jun 21 2016 11:30
which link??? @rishabh-saxena
Rishabh Saxena
@rishabh-saxena
Jun 21 2016 11:31
briantford.com the last link in this website.....
Mohamed Nasrullah
@nasr18
Jun 21 2016 11:31
the link shared by @ishikawayoshi looks good. follow that.
Rishabh Saxena
@rishabh-saxena
Jun 21 2016 11:32
@nasr18 thanks....
joystick
@joystick
Jun 21 2016 14:27
Hi, is there any example on using mongoose with fibers please?
M S Morris
@msmfsd
Jun 21 2016 22:56
If I have a findOneAndUpdate and the update data is dynamic, could be any one or more fields being updated, how do avoid deleting properties inside an object that are not being updated? see http://stackoverflow.com/questions/37933294/mongoose-findoneandupdate-deletes-nested-vars
Blake Kostner
@btkostner
Jun 21 2016 23:31
convert it to dot form then update
{ "myvar.useDefault": false }
M S Morris
@msmfsd
Jun 21 2016 23:38
But I dont know what values are being updated, it could be myvar.useDefault or it could be mayvar.custom or myvar.default? The operation updates one field and deletes any other fields not passed in the request?
M S Morris
@msmfsd
Jun 21 2016 23:46
OK I looked into dot form and that helps a lot thanks. I still am hazy on the best way to update when I have no idea what fields are being updated, should i loop throught the request possibly?
Blake Kostner
@btkostner
Jun 21 2016 23:48
there are a bunch of functions online for converting objects to dot notation and back. here is mine: https://github.com/elementary/houston/blob/master/src/lib/helpers/dotNotation.js
basically just convert the whole request object to dot notation, filter the ones you want updated (don't want people updating passwords :P), then run the update function
M S Morris
@msmfsd
Jun 21 2016 23:50
Perfect thanks Blake that makes sense now. Much appreciated.
Blake Kostner
@btkostner
Jun 21 2016 23:50
np. enjoy