zhu jun~ 2016-12-19 05:00 采纳率: 100%
浏览 1770
已结题

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中的$的含义和作用是什么。

  • 写回答

2条回答 默认 最新

  • oyljerry 2016-12-19 06:07
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向