Mongodb中"$"的的含义是什么,示例如下:

文档的结构如下:
{
"_id" : ObjectId("57302832d4c6025e3e44b1bc"),
"_class" : "com.sumridge.smart.entity.CompanyInfo",
"accountInfos" : [
{
"_class" : "com.sumridge.smart.entity.AccountInfo",
"_id" : ObjectId("57302848d4c6025e3e44b1be"),
"portfolios" : [
{
"title" : "test1",
"list" : [
{
"_class" : "com.sumridge.smart.entity.PortfolioInfo",
"cusip" : "001",
"quantity" : 100,
"price" : 9.5
}
]
}]
}
]
}
我现在要向accountInfos数组下匹配到的accountInfo对象的portfolios的属性中增加一个文档,这里portfolios也是一个数组。
我的代码如下:
db.companyInfo.update(
{"accountInfos._id":ObjectId("57302848d4c6025e3e44b1be")},
{$addToSet:
{
"accountInfos.$.portfolios":
{
title:"test_11",
list:{cusip:"001",quantity:1,price:1}
}
}
}
)
这样我就能对子文档中的数组进行插入操作,我想问的问题就是accountInfos.$.portfolios中的$的含义和作用是什么。

The positional $ operator identifies an element in an array to update without explicitly specifying the position of the element in the array. To project, or return, an array element from a read operation, see the $ projection operator.

The positional $ operator has the form:

{ ".$" : value }
When used with update operations, e.g. db.collection.update() and db.collection.findAndModify(),

the positional $ operator acts as a placeholder for the first element that matches the query document, and
the array field must appear as part of the query document.

后面那个类是前面那个类的内部类。