- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
例如,有一个名为 test
的集合,其中包含以下文档:
{
"_id" : ObjectId("5692ac4562c824cc5167379f"),
"list" : [
{
"name" : "elem1",
"type" : 1
},
{
"name" : "elem2",
"type" : 2
},
{
"name" : "elem3",
"type" : 1
},
{
"name" : "elem4",
"type" : 3
},
{
"name" : "elem4",
"type" : 2
}
]
}
假设我想检索 仅 list
中匹配的那些子文档的列表:
类型 = 2
。我尝试了以下查询:
db.getCollection('test').find({
'_id': ObjectId("5692ac4562c824cc5167379f"),
'list.type': 1
})
但我得到的结果包含 list
中的 every 子文档,我猜这是因为 list
中至少有一个文档是输入等于 1。
取而代之的是,我想获得的结果是 list
中匹配 'list.type': 1
的每个子文档:
{
"_id" : ObjectId("5692ac4562c824cc5167379f"),
"list" : [
{
"name" : "elem1",
"type" : 1
},
{
"name" : "elem3",
"type" : 1
}
]
}
...所以 $
和 $elemMatch
并不是我真正想要的,因为它们只返回第一个匹配的元素。
有人知道如何实现我的目标吗?
最佳答案
db.myCol.aggregate([
{ $unwind: "$list" },
{ $match: { "list.type":1 } },
{ $group: { "_id":"$_id", list: {$push:"$list"}} }
])
关于mongodb - 蒙戈 : how to retrieve ONLY subdocs that match certain properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34710018/
我正在使用此代码从特定文档中获取子文档 DocumentFragment result= bucket.async().lookupIn(docId).get(subDocId).execute()
您好,我在推送新子文档之前检查子文档是否存在时遇到此问题。 var UserSchema = new Schema({ name : String, app_key
我有以下模型: var Customer = mongoose.model('Customer', { firstname : String, lastname : String,
我目前设置了以下 Mongoose 模型: var Customer = mongoose.model('Customer', { firstname : String, lastna
例如,有一个名为 test 的集合,其中包含以下文档: { "_id" : ObjectId("5692ac4562c824cc5167379f"), "list" : [
我正在尝试做什么。 我有一个包含 operationCountSchema 对象列表的 userSchema。我想要做的是创建一个静态方法来更新这些操作计数子文档之一上的 count 字段(如果它存在
假设我有一个名为 LeagueSchema 的架构,它需要包含有关联赛的一些一般信息(例如名称、创建时间等)以及一些更复杂的对象(例如成员(member)资格)。因为这些成员(member)在联盟之外
我正在尝试使用 .create() 插入子文档,并使用 .id() 查询所述文档。我一直在关注指南 here 我收到错误:对象没有方法“id()”或“create()” 下面是我的代码: /db/sc
我是一名优秀的程序员,十分优秀!