jjzjj

MongoDB - "The dollar ($) prefixed field\' $$hashKey\' in\' 字段名".$$hashKey\' is not valid for storage.' "

coder 2023-10-29 原文

在尝试更新文档时,我在字段 timesToDisplay 中收到上述错误。

MongoDB 版本 2.6.7。

整个模型:

msg = {
          'name': '',
          'template': '',
          'displayDurInMilliSec': 0,
          'timesToDisplay': [],
          'images': [],
          'texts': [],
          'screen': []
       }

我想我会在其他 3 个数组字段中遇到同样的错误。

我试过使用 $set 但仍然遇到同样的错误。

代码:

function updateMessage(msg) {
    var conditions = {_id: msg._id}
      , update = { 'name': msg.name,
                   'template': msg.template,
                   'displayDurInMilliSec': msg.displayDurInMilliSec,
                   'timesToDisplay': msg.timesToDisplay,
                   'images': msg.images,
                   'texts': msg.texts,
                   'screen': msg.screen
    }

    messageModel.update(conditions, update, callback);

    function callback(err, numAffected) {
        if (!err) console.log(numAffected)
        else console.log(err)
    }
}

编辑 msg 参数本身就是一个文档:

{ _id: '557d58abd54955480db6694f',
  name: 'msg99',
  timesToDisplay: [ { startDate: '2015-06-19T21:00:00.000Z',
                   '$$hashKey': 'object:214',
                    endDate: '2015-06-25T21:00:00.000Z',
                    daysOfTheWeek: [Object],
                    startTimeOfDay: '11',
                    endTimeOfDay: '13' } ],
 images: [],
 texts: [],
 screen: [ 1 ],
 '$$hashKey': 'object:54',
 displayDurInMilliSec: '40189',
 template: 'templates/Template2.html' }

最佳答案

$$hashkey 字段是 AngularJS 在使用 ngRepeat 或 ngOptions 时添加的。在 ngRepeat 的情况下,您可以通过将 track by $index 附加到它来更改重复字符串。要使用 ngOptions,您必须自己过滤掉该字段。 AngularJS 提供了一个快速的过滤方法:angular.toJson。这将过滤掉所有以两个美元符号为前缀的字段。 Check out the documentation .

我意识到这不是 MongoDB 的答案,但这个特定错误($$hashkey)通常是由于 AngularJS 造成的。

关于MongoDB - "The dollar ($) prefixed field\' $$hashKey\' in\' 字段名".$$hashKey\' is not valid for storage.' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30829208/

有关MongoDB - "The dollar ($) prefixed field\' $$hashKey\' in\' 字段名".$$hashKey\' is not valid for storage.' "的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  4. ruby-on-rails - Rails 源代码 : initialize hash in a weird way? - 2

    在rails源中:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb可以看到以下内容@load_hooks=Hash.new{|h,k|h[k]=[]}在IRB中,它只是初始化一个空哈希。和做有什么区别@load_hooks=Hash.new 最佳答案 查看rubydocumentationforHashnew→new_hashclicktotogglesourcenew(obj)→new_has

  5. ruby-on-rails - Rails 3 I18 : translation missing: da. datetime.distance_in_words.about_x_hours - 2

    我看到这个错误:translationmissing:da.datetime.distance_in_words.about_x_hours我的语言环境文件:http://pastie.org/2944890我的看法:我已将其添加到我的application.rb中:config.i18n.load_path+=Dir[Rails.root.join('my','locales','*.{rb,yml}').to_s]config.i18n.default_locale=:da如果我删除I18配置,帮助程序会处理英语。更新:我在config/enviorments/devolpment

  6. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  7. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  8. ruby - 在 jRuby 中使用 'fork' 生成进程的替代方案? - 2

    在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',

  9. ruby-on-rails - 如何验证非模型(甚至非对象)字段 - 2

    我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss

  10. ruby-on-rails - form_for 中不在模型中的自定义字段 - 2

    我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢

随机推荐