首页 \ 问答 \ 使用mongodb中对象字段的值创建新的数组字段(Create new array field with values from object field in mongodb)

使用mongodb中对象字段的值创建新的数组字段(Create new array field with values from object field in mongodb)

鉴于在我的数据库中,我有这样的对象:

_id: 1,
class: 'x',
urls: {
  'a': '/someAUrl',
  'b': '/someBUrl'
}

我想运行一个脚本,将这些对象转换为:

_id: 1,
class: 'x',
urls: {
  'a': '/someAUrl'
},
urls2: [
  {type:'a', url:'/someAUrl'}
]

必须保留初始URL字段。 我尝试在mongo shell中运行这样的东西但没有成功:

db.eval(db.test.find({ class: 'x' }).snapshot().forEach(   function (e) {     e.urls2 = [{ url: e.urls.a, type: 'a'}];     db.test.save(e);   } ))

有任何想法吗? 谢谢!


Given that in my db I have objects like this:

_id: 1,
class: 'x',
urls: {
  'a': '/someAUrl',
  'b': '/someBUrl'
}

I would like to run a script that transforms those objects to:

_id: 1,
class: 'x',
urls: {
  'a': '/someAUrl'
},
urls2: [
  {type:'a', url:'/someAUrl'}
]

The initial urls field must remain. I tried running something like this inside mongo shell with no success:

db.eval(db.test.find({ class: 'x' }).snapshot().forEach(   function (e) {     e.urls2 = [{ url: e.urls.a, type: 'a'}];     db.test.save(e);   } ))

Any ideas? Thanks!


原文:https://stackoverflow.com/questions/38488037
更新时间:2023-01-10 21:01

最满意答案

要访问特定行的特定列值,请使用

myTableData.Rows(rowNumber)(columnNumber) 

要么

myTableData.Rows(rowNumber).Item(columnNumber)

To access a particular column value of a particular row, use

myTableData.Rows(rowNumber)(columnNumber) 

or

myTableData.Rows(rowNumber).Item(columnNumber)

相关问答

更多
  • .Net平台引入了很多先进的技术,导致了VB6和VB.Net之间产生了一个巨大的鸿沟 就语言功能上来讲,VB.net完全是为了.Net技术而生,具有更好的运行效率和更加强大的功能(某些方面甚至超过了C#) 从语法角度上来讲,VB.net成为了真正的OOP(面向对象语言),不但支持类的继承、派生,还支持委托、泛型等等更加高级的编程技术 如果你是从VB6升级到.net的话,建议要将VB.net当作一门新的语言来学。以VB6的经验来应用到VB.net上是会犯很多错误的 关于从VB6升级到VB.net的代 ...
  • .Net平台引入了很多先进的技术,导致了VB6和VB.Net之间产生了一个巨大的鸿沟 就语言功能上来讲,VB.net完全是为了.Net技术而生,具有更好的运行效率和更加强大的功能(某些方面甚至超过了C#) 从语法角度上来讲,VB.net成为了真正的OOP(面向对象语言),不但支持类的继承、派生,还支持委托、泛型等等更加高级的编程技术 如果你是从VB6升级到.net的话,建议要将VB.net当作一门新的语言来学。以VB6的经验来应用到VB.net上是会犯很多错误的 关于从VB6升级到VB.net的代码变换问题 ...
  • 要使用负十六进制int16常量,请在值前面加上FFFF。 似乎十六进制常量在vb.net中是int32(至少)。 dim w as int16 w = &HFFFF8589 To use a negative hex int16 constant, precede the value with FFFF. It seems that hex constants are int32 (at least) in vb.net. dim w as int16 w = &HFFFF8589
  • GetEnumerator()是完全等价的。 它在代码中作为NewEnum公开。 只需实现System.Collections.IEnumerable接口,即非泛型接口。 GetEnumerator() is the exact equivalent. It gets exposed as NewEnum in code. Simply implement the System.Collections.IEnumerable inte ...
  • 不要使用* A版本,只需跳过后缀,并使用StringBuilder而不是String: Private Declare Auto Function GetWindowText Lib "user32" (ByVal hwnd As Integer, ByVal lpWindowText As StringBuilder, ByVal cch As Integer) As Integer Private Declare Function GetWindowTextLength Lib "user32" (By ...
  • 要访问特定行的特定列值,请使用 myTableData.Rows(rowNumber)(columnNumber) 要么 myTableData.Rows(rowNumber).Item(columnNumber) To access a particular column value of a particular row, use myTableData.Rows(rowNumber)(columnNumber) or myTableData.Rows(rowNumber).Item(colu ...
  • 来自MSDN Library: AscB函数与包含在字符串中的字节数据一起使用。 AscB返回第一个字节,而不是返回第一个字符的字符代码 所以以下应该工作: Encoding.ASCII.GetBytes(value).First 价值是一个Char Gent, many thanks for your replies... The code I had was part of an MD5 encryption class written in VB6. Over the weekend I came ...
  • Open strFileName For Output As #FileHandle% MousePointer = vbHourglass Print #FileHandle%, strText MousePointer = vbDefault Close #FileHandle% 转换为VB.NET代码: Me.Cursor = Cursors.WaitCursor Using fs As New StreamWriter(strFileName, Fa ...
  • 有关从Visual Basic 6调用.Net类的完整文章: http : //www.devsource.com/c/a/Using-VS/Calling-Net-Classes-from-Visual-Basic-6/ 使用VS 2005创建COM DLL:步骤: http : //www.codeproject.com/KB/COM/VS2005ComDllWalkThru.aspx A complete article about Calling .Net Classes from Visual B ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。