-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not printing table data correctly in case of mongoose JSON array response #18
Comments
Try to convert the returned model into a plain object, maybe there is a method like “toJson”?
…Sent from my iPhone
On Jul 24, 2018, at 12:09, Suresh Prajapati ***@***.***> wrote:
I am trying to print mongoose json array using console.table, However I see unexpected table header. Below is my code:
const cTable = require('console.table');
const mongoose = require('mongoose');
mongoose.connect('mongodb:/host', {
auth: {
user: 'unm',
password: 'pwd'
}
});
const pairNm = 'BTC-INR-tx'
const pairModel = mongoose.model(pairNm, {}, pairNm);
pairModel.find({}, {_id: 0, trans_id: 1,
fill_qty: 1,
fill_price: 1,
fill_flags: 1,
currencyPair: 1,
lastModifiedDate: 1}).limit(10).exec().then((d) => {
// console.log(d);
console.table('d', d);
});
Here is the log:
d
------------------------------------------------------
$__ isNew errors _doc $init
--------------- ----- ------ --------------- -----
[object Object] false [object Object] true
[object Object] false [object Object] true
[object Object] false [object Object] true
[object Object] false [object Object] true
[object Object] false [object Object] true
[object Object] false [object Object] true
[object Object] false [object Object] true
[object Object] false [object Object] true
[object Object] false [object Object] true
[object Object] false [object Object] true
Whereas actual data look like this:
[ { trans_id: 382,
fill_qty: 10000000,
fill_price: 712500,
fill_flags: 3,
currencyPair: 'BTC-INR',
lastModifiedDate: 1521712287144 },
{ trans_id: 384,
fill_qty: 5000000,
fill_price: 711800,
fill_flags: 2,
currencyPair: 'BTC-INR',
lastModifiedDate: 1521714892456 },
{},
{ trans_id: 392,
fill_qty: 10000000,
fill_price: 711200,
fill_flags: 1,
currencyPair: 'BTC-INR',
lastModifiedDate: 1521787237696 },
{ trans_id: 393,
fill_qty: 10000000,
fill_price: 711200,
fill_flags: 3,
currencyPair: 'BTC-INR',
lastModifiedDate: 1521787298539 },
{ trans_id: 394,
fill_qty: 21168,
fill_price: 715000,
fill_flags: 2,
currencyPair: 'BTC-INR',
lastModifiedDate: 1521790941289 },
{ trans_id: 395,
fill_qty: 978832,
fill_price: 715000,
fill_flags: 3,
currencyPair: 'BTC-INR',
lastModifiedDate: 1521791070426 },
{ trans_id: 399,
fill_qty: 100000000,
fill_price: 716000,
fill_flags: 3,
currencyPair: 'BTC-INR',
lastModifiedDate: 1521798458247 },
{ trans_id: 400,
fill_qty: 22510000,
fill_price: 710000,
fill_flags: 2,
currencyPair: 'BTC-INR',
lastModifiedDate: 1521800843473 },
{ trans_id: 400,
fill_qty: 77490000,
fill_price: 709000,
fill_flags: 1,
currencyPair: 'BTC-INR',
lastModifiedDate: 1521800843474 } ]
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Well, It's resolved by converting it to plain js object by using mongoose's lean Below is the modified code:
Which results in beautiful tabled response:
|
Mongoose response is not a plain js object, It has to be converted first before converting it to table structure. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying to print mongoose json array using console.table, However I see unexpected table header. Below is my code:
Here is the log:
Whereas actual data look like this:
The text was updated successfully, but these errors were encountered: