bp123
bp123

Reputation: 3417

Find returns object on child element

I'm trying to find all the fruit in my database where the colour is not red however when I run the find command below it returns [object]. What am I doing wrong

database: mongoDB

"fruit": {
    "color": [
      "red"
    ]
  }

Path: server.js

 var fruit = fruit.find({
                    "fruit.color": { $nin: [ red ] },
                  }).fetch();

If I console log on the server it retuns the following.

console.log(fruit);

{ color: [Object] } } ]

Upvotes: 0

Views: 81

Answers (1)

HoefMeistert
HoefMeistert

Reputation: 1200

Your find returns an array of objects, that's why you get the [object] result. You have to iterate the result. Like:

var fruits = fruit.find({
                    "fruit.color": { $nin: [ red ] },
                  }).fetch();

fruits.forEach(function (afruit) {
            console.log(afruit.color);
        });

Upvotes: 1

Related Questions