Lab-$unwind-the question is not specific

Hi,
Lab-$unwind -the question is not specific.
Please help.
MongoDB Enterprise Cluster0-shard-0:PRIMARY> var pipeline = [
…< deleted >
MongoDB Enterprise Cluster0-shard-0:PRIMARY> printjson(db.movies.aggregate(pipeline).next());
< deleted >
MongoDB Enterprise Cluster0-shard-0:PRIMARY> 2019-04-21T23:29:17.792-0500 W NETWORK [ReplicaSetMonitor-TaskExecutor] Failed to check socket connectivity: The operation completed successfully.
2019-04-21T23:29:18.022-0500 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to cluster0-shard-00-00-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-00-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-04-21T23:29:18.078-0500 W NETWORK [ReplicaSetMonitor-TaskExecutor] Failed to check socket connectivity: The operation completed successfully.
2019-04-21T23:29:18.311-0500 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to cluster0-shard-00-01-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-01-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-04-21T23:29:18.355-0500 W NETWORK [ReplicaSetMonitor-TaskExecutor] Failed to check socket connectivity: The operation completed successfully.
2019-04-21T23:29:18.586-0500 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to cluster0-shard-00-02-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-02-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-04-22T05:47:27.719-0500 W NETWORK [ReplicaSetMonitor-TaskExecutor] Failed to check socket connectivity: The operation completed successfully.
2019-04-22T05:47:28.343-0500 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to cluster0-shard-00-00-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-00-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-04-22T05:47:28.436-0500 W NETWORK [ReplicaSetMonitor-TaskExecutor] Failed to check socket connectivity: The operation completed successfully.
2019-04-22T05:47:29.033-0500 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to cluster0-shard-00-01-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-01-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-04-22T05:47:29.097-0500 W NETWORK [ReplicaSetMonitor-TaskExecutor] Failed to check socket connectivity: The operation completed successfully.
2019-04-22T05:47:29.366-0500 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to cluster0-shard-00-02-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-02-jxeqq.mongodb.net:27017 with a 5 second timeout)

MongoDB Enterprise > show dbs
2019-04-22T05:48:31.511-0500 I NETWORK [js] Marking host cluster0-shard-00-00-jxeqq.mongodb.net:27017 as failed :: caused by :: Location40657: Last known master host cannot be reached
100YWeatherSmall 0.117GB
admin 0.000GB
aggregations 0.067GB
citibike 0.361GB
city 0.002GB
config 0.000GB
coursera-agg 0.083GB
local 1.076GB
mflix 0.458GB
results 0.000GB
ships 0.001GB
video 0.448GB
MongoDB Enterprise > use aggregations
switched to db aggregations
MongoDB Enterprise > show collections
air_airlines
air_alliances
air_routes
bronze_banking
child_reference
customers
employees
exoplanets
gold_banking
icecream_data
movies
nycFacilities
parent_reference
silver_banking
solarSystem
stocks
system.views
MongoDB Enterprise >

@SUBRAMANIAN_29141

In what way do you think it’s not specific? You are intended to post the answer in the following format:

{ "_id": "First Last", "numFilms": 1, "average": 1.1 }

which seems pretty specific to me.

BTW, I’m not at all sure why you’ve posted most of the information above or what it’s supposed to add to your question. However, I would remind you that we do request that you do not post code or answers (or potential answers) here in the Forum. I have edited you post to remove those. Thanks for your future cooperation.

hi,

I, doubt $trunc can be used for desired result . As $trunc - Truncate a number to its integer.

{ $trunc : }

The expression can be any valid expression as long as it resolves to a number.

Please clarify.

with regards,

@SUBRAMANIAN_29141

Ahh… so your problem isn’t that the question isn’t specific, but that you can’t figure out how to get the desired result in decimal places.

As a matter of fact, $trunc is exactly what you want. Mathematically, what you want to do is multiply the given number by the desired power of 10, corresponding to the number of decimal places you want, then truncate that result to an integer, then divide the result by the same power of 10. In the instant case, this is something like

($average * 10) --> $trunc {$result} --> ($result / 10)

I’ll leave it to you to turn that into proper MongoDB aggregation commands. Good luck.

hi,
THANKS

with regards,

hi,
It is my Good luck!
Please read the following,
Reference > Operators > Aggregation Pipeline Operators > $round (aggregation)
$round (aggregation)
$round
New in version 4.2…
$round rounds a number to to a whole integer or to a specified decimal place.
$round has the following syntax:
{ $round : [ , ] }
Field Type Description
number
Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long.

© MongoDB, Inc 2008-present. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc.

Just a pointer here.

4.2 added the ability to add truncate to 20 decimal places just like $round, and in the question it says truncate, since $round rounds up and down.

In this question it doesn’t affect the actual result, but it could have.