我有一个包含日期的文件,我想按季度分组文件.我怎么能在MongoDB中做到这一点?
我的架构是:
var ekgsanswermodel = new mongoose.Schema({
userId: {type: Schema.Types.ObjectId},
topicId : {type: Schema.Types.ObjectId},
ekgId : {type: Schema.Types.ObjectId},
answerSubmitted :{type: Number},
dateAttempted : { type: Date},
title : {type: String},
submissionSessionId : {type: String}
});
Run Code Online (Sandbox Code Playgroud)
第一季度包含第1,2,3个月.第二季度包含第4季度,第5季度,第6季度等第4季度.我的最终答案应该是:
"result" : [
{
_id: {
quater:
},
_id: {
quater:
},
_id: {
quater:
},
_id: {
quater:
}
}
Run Code Online (Sandbox Code Playgroud) 我的文档包含一个数组,如:
{
"differentialDiagnosis" : "IART/Flutter",
"explanation" : "The rhythm.",
"fileName" : "A115a JPEG.jpg",
"history" : "1 year old with fussiness",
"interpretationList" : [
{
"interpretations" : [
ObjectId("54efe7c8d6d5ca3d5c580a22"),
ObjectId("54efe80bd6d5ca3d5c580a26")
]
},
{
"interpretations" : [
ObjectId("54efe80bd6d5ca3d5c580a26"),
ObjectId("54efe82ad6d5ca3d5c580a28")
]
}
],
}
Run Code Online (Sandbox Code Playgroud)
我想删除所有出现的ObjectId("54efe80bd6d5ca3d5c580a26"),但我写了一个查询:
db.ekgs.update({'interpretationList.interpretations':ObjectId("54c09fb3581c4c8c218d1a40")}, {$pull:{ 'interpretationList.$.interpretations':{ ObjectId("54c09fb3581c4c8c218d1a40")}})
Run Code Online (Sandbox Code Playgroud)
这仅删除第一次出现的ObjectId("54efe80bd6d5ca3d5c580a26")。
我想在文档的嵌套数组中应用skip和limit for paging如何执行此操作[Efficient Way]
我的文件记得像
{
"_id":"",
"name":"",
"ObjectArray":[{
"url":"",
"value":""
}]
}
Run Code Online (Sandbox Code Playgroud)
我想检索多个文档,每个文档包含'n'个记录.
我$in在查找查询中使用基于_id检索多个记录但是如何ObjectArray 在每个文档中获得一定数量的元素?