集計:ネストされたドキュメント(ネストされたオブジェクト)で日付をグループ化し、カウントを表示しますか?
集約には、MongoDBのaggregate()を使用します。 $groupで日付をグループ化します。ドキュメントを使用してコレクションを作成しましょう-
> db.demo717.insertOne(
... {
... "shippingdetails":
... [
... {
... duedate:"2020-04-29 22:33:04",
... },
... {
... duedate:"2020-03-29 22:33:04",
... },
... {
... duedate:"2020-04-29 22:33:04",
... },
... {
... duedate:"2020-01-29 22:33:04",
... }
... ]
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5ea9b3cd85324c2c98cc4c30")
} find()メソッドを使用してコレクションからすべてのドキュメントを表示する-
> db.demo717.find().pretty();
これにより、次の出力が生成されます-
{
"_id" : ObjectId("5ea9b3cd85324c2c98cc4c30"),
"shippingdetails" : [
{
"duedate" : "2020-04-29 22:33:04"
},
{
"duedate" : "2020-03-29 22:33:04"
},
{
"duedate" : "2020-04-29 22:33:04"
},
{
"duedate" : "2020-01-29 22:33:04"
}
]
}> 以下は、ネストされたドキュメント(ネストされたオブジェクト)の日付をグループ化するための集計のクエリです-
> db.demo717.aggregate(
... {
... $unwind:"$shippingdetails"},
... {
... $group: {
... _id: "$shippingdetails.duedate",
... count: {
... $sum: 1
... }
... }
... }
... ) これにより、次の出力が生成されます-
{ "_id" : "2020-01-29 22:33:04", "count" : 1 }
{ "_id" : "2020-03-29 22:33:04", "count" : 1 }
{ "_id" : "2020-04-29 22:33:04", "count" : 2 } -
JavaScriptはJSONオブジェクトを2つのプロパティでグループ化し、カウントします
このようなオブジェクトの配列があるとします- const arr = [ {"location":"Kirrawee","identity_long":"student"}, {"location":"Kirrawee","identity_long":"visitor"}, {"location":"Kirrawee"
-
iOSアプリケーションで現在の日付と時刻を表示するにはどうすればよいですか?
日付と時刻を操作することは、どのプログラミング言語でも非常に重要です。モバイルアプリケーションを開発している場合は、さらに重要になります。 天気、天気予報、ゲームなどの多くのアプリケーションは、日付と時刻を使用します。ここでは、現在の日付と時刻を取得する方法を確認します。 現在の日時を取得するには、timeIntervalSince1970インスタンスプロパティを使用します。これについては、https://developer.apple.com/documentation/foundation/nsdate/1407504-timeintervalsince1970を参照してください。