0

Here is my Simple Find Query in Mongoose

 CustomerModel.find({},function (err, result) {
            console.log(result);

      })

In Console

[ { _id: 5a081297b028f45d691f0257,
    name: 'Panindra',
    contact: { _id: 5a08191b5667530e0844f3a8, mobile: [Array] } } ]

I was expecting my Mobile Result shoulde some thing like this

mobile:['88842XXXXXX']

but I am getting mobile:[Array];

Here is my MONGOS SHELL QUERY RESULT :

db.getCollection('tests').find({})

{ "_id" : ObjectId("5a081297b028f45d691f0257"), "name" : "Panindra", "contact" : { "mobile" : [ "88842XXXXXX" ] } }

and Here is my SCHEMA for Customer and Contact ..

  var CustomerSchema = new Schema({
    name: String,
    contact: new Schema({
        mobile:[String]

    })

How to Get Mobile Value in find () Query ??

NOTE : BUT IF I QUERY FOR findOne() ? I am getting the mobile numbers , What i am missing ? here is query

 CustomerModel.findOne({name:"Panindra"},function (err, result) {

            console.log(result);

      })

and the result ( as I desired)

IN CONSOLE

  { _id: 5a081297b028f45d691f0257,
      name: 'Panindra',
      contact: { _id: 5a081a8ea0fba80b10c0e1c6, mobile: [ '88842XXXXX' ] } }
  • That means the [most upvoted answer](https://stackoverflow.com/a/4293047/2313887) if for some reason that is not obvious. `console.log(JSON.stringify(result, undefined, 2))` will give you something more akin to what you are expecting to see. The `mongo` shell pretty much does that "under the hood" for you. So that's why it looks clear to you there. – Neil Lunn Nov 12 '17 at 10:02
  • @neil Lunn You mean its related to javascript issue ?? – Freelancer Pan Nov 12 '17 at 10:03
  • Well sort of. It's just how it has always worked. `console.log()` does not do "pretty" with objects on it's own. That's why you `JSON.stringify()`. – Neil Lunn Nov 12 '17 at 10:04
  • OK thank You . I got , I got Result . Shall I remove this question , I am new to this forum , – Freelancer Pan Nov 12 '17 at 10:06
  • You can do what you like. Deleting is not really the great idea some people think it is, so I would generally leave it. – Neil Lunn Nov 12 '17 at 10:07

0 Answers0