Mongodb文档重命名字段不起作用

编程入门 行业动态 更新时间:2024-10-24 10:14:07
本文介绍了Mongodb文档重命名字段不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

{ 一般:{ 设置:[ { 名称:{ MetaData:{ type : bool } } }, { 名称:{ MetaData:{ type: bool } } }, { 名称:{ MetaData:{ type: bool } } } ] } } i有上述文件我需要更新General.Setting。[index ] .Name.MetaData.type to General.Setting。[index] .Name.MetaData.Newtype

我尝试过: i尝试使用此查询: 第一种方法: doc.forEach(function(d){ var settingsCollectionJSON = d.General.Setting; settingsCollectionJSON.forEach(function(temp){ var settingsCollectionJSONobj = temp.Name.MetaData.Loc alizable; db.getCollection('SettingCollection')。update(temp,{$ rename:{Name.MetaData.type:Name.MetaData.Newtype}}) }) }) 使用$ set和$ unset的第二种方法。 //db.getCollection('SettingCollection').update(temp, {$ set:{'MetaData.0.type':settingsCollectionJSONobj},$ unset:{'MetaData.0.Newtype':1} }) 但对于这些我没有得到更新。我有任何解决方案吗?

解决方案

rename:{Name.MetaData.type:Name.MetaData.Newtype}}) }) } ) 第二种方法使用

set和

取消设置。 //db.getCollection('SettingCollection').update(temp, {

{ "General": { "Setting": [ { "Name": { "MetaData": { "type": "bool" } } }, { "Name": { "MetaData": { "type": "bool" } } }, { "Name": { "MetaData": { "type": "bool" } } } ] } } i have the above document i need to update General.Setting.[index].Name.MetaData.type to General.Setting.[index].Name.MetaData.Newtype

What I have tried: i did tried using this query : 1st approach: doc.forEach( function(d) { var settingsCollectionJSON = d.General.Setting; settingsCollectionJSON.forEach( function(temp) { var settingsCollectionJSONobj = temp.Name.MetaData.Localizable; db.getCollection('SettingCollection').update(temp, { $rename: { "Name.MetaData.type": "Name.MetaData.Newtype" } }) }) }) 2nd approach using $set and $unset. //db.getCollection('SettingCollection').update(temp, { $set:{'MetaData.0.type':settingsCollectionJSONobj}, $unset: {'MetaData.0.Newtype':1} }) but for both these i'm not getting updated.can i have any solution?

解决方案

rename: { "Name.MetaData.type": "Name.MetaData.Newtype" } }) }) }) 2nd approach using

set and

unset. //db.getCollection('SettingCollection').update(temp, {

更多推荐

Mongodb文档重命名字段不起作用

本文发布于:2023-11-22 13:07:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617535.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   重命名   不起作用   文档   Mongodb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!