0

Actually I want to aggregate based on username and contain place information. It is working fine with the mongo shell

db.demo_datas.aggregate([{"$group":{"_id":"$user_screenname", "place":{"$push":{"place":"$user_geo"}}}}]);

{
"_id" : "orena001",
"place" : [
    {
        "place" : [
            11.158983,
            78.163335
        ]
    },
    {
        "place" : [
            11.137964,
            78.16126
        ]
    }
]

}

Now, when i used with node.js mongoose the place array is not returning the values. The mongoose node.js query is

   demodatas.aggregate([{$group:{"_id":"$user_screenname", "place":{"$push":{"place":"$user_geo"}}}}], function(err, data){

console.log(data);
});

but it returns result like this.

{ _id: 'orena001',
    place: 
     [ [Object],
       [Object] 
     ]
}

could any one help me to resolve this issues. Thanks advance.

1 Answer 1

1

Consider the following:

> console.log({ foo : { bar : [ { xxx : 1 } ] } })
{ foo: { bar: [ [Object] ] } }

This is showing similar output to what you are seeing. The reason for the unexpected output is that a regular console.log() will only show nested objects up to a specific depth, after which it will abbreviate the output (in this case, it will show [Object] instead of the actual object). This doesn't mean the object is invalid, though, it's just shown in this shorter format when you print it.

One solution to get to see the whole object is to convert it to JSON first:

> console.log('%j', { foo : { bar : [ { xxx : 1 } ] } })
{"foo":{"bar":[{"xxx":1}]}}

Or, in your case:

console.log('%j', data);
Sign up to request clarification or add additional context in comments.

1 Comment

Hello @robertklep Thanks a lot.. It works great..nearly I wasted one night to resolve it .. Thanks again.. Have a great Day..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.