These are chat archives for Automattic/mongoose

9th
Mar 2017
Anderson Anzileiro
@anzileiro
Mar 09 2017 04:40
@cristiandav hey guy, you should try to use .reduce()
Tulsi Sapkota
@Tolsee
Mar 09 2017 07:52

Hello Everyone,

I want to build a API service which gives client a leverage to create Documents and Fields by their own. I am currently using mongoose. It would be great anyone can help me out.

Pieter Stokkink
@forkerino
Mar 09 2017 12:12

Hello.
Got this as part of my code:

CoinSet.find({},function(err, data){
  if (err) throw err;
  console.log("data : " + data);
  console.log("data.coins : " + data.coins);

Output is as follows:

data : { _id: 58c13f1cd3a2a030e4efbf94,
  __v: 0,
  coins: [ 'BTC', 'ETH', 'DASH', 'LTC' ] }
data.coins : undefined

typeof data is object.
What am I doing wrong?
trying to access the coins array.

Tulsi Sapkota
@Tolsee
Mar 09 2017 15:25
@forkerino CoinSet.find() will return list of data so, you may use for loop to access a single data and then data.coins. Or you can use findOne() method.
Pieter Stokkink
@forkerino
Mar 09 2017 15:49
@Tolsee thanks!
got it to work.
Diego Aguilar Aguilar
@diegoaguilar
Mar 09 2017 17:17
Hello, how can I pront query object?
like I have a query instance and it finds where user is great than 10 so I can print and get {user: {$gte: 10}}
Anderson Anzileiro
@anzileiro
Mar 09 2017 18:35
@cristiandav // let dictionary = [{ '5': 50, '6': 60 }, { 'A': 10 }, { 'YEEZY': 30 }]
// let total = 0;
// let keys = dictionary.map(dict => total += Object.keys(dict).map(c => dict[c]).reduce((ant, prox) => ant + prox, 0))
// console.log(' total', total);