首页 \ 问答 \ Mongoid删除嵌入式文档不会持续(Mongoid deleting embedded documents does not persist)

Mongoid删除嵌入式文档不会持续(Mongoid deleting embedded documents does not persist)

我几个小时就遇到了一个问题,并且Google自己没有任何意义。

我有一个嵌入式文档的Mongoid模型,如下所示:

embeds_many :tags, :as => :taggable

出于某种原因,尝试删除此文档似乎在控制台中工作,但在重新加载之后文档会返回。 我已经尝试了以下内容:

model.tags.delete_all

model.tags.each do |tag|
  tag.delete
end

model.tags.destroy_all

完成上述所有操作后,我可以确认model.tags返回一个空数组。 然后为了安全起见,我甚至打电话给model.save。 如果我重新加载模型,所有嵌入的标签都会返回。

使用Mongoid删除嵌入文档的正确方法是什么?


I have been running into an issue for hours and have Googled myself senseless.

I have a Mongoid model with an embedded document, like so:

embeds_many :tags, :as => :taggable

For some reason, attempting to delete this document appears to work in the console but then the documents come back after a reload. I have tried the following:

model.tags.delete_all

model.tags.each do |tag|
  tag.delete
end

model.tags.destroy_all

After all of the above, I can confirm that model.tags returns an empty array. Then to be safe, I even call model.save. If I reload the model, all of the embedded tags come back.

What is the correct way to delete embedded documents using Mongoid?


原文:https://stackoverflow.com/questions/9972089
更新时间:2021-11-08 18:11

最满意答案

Unix crontab有5个字段 ; 分钟,小时,月,月,星期几。

这一行:

every '* * * * * *' do
       1 2 3 4 5 6 <- Error

你输入的字段太多了。


The Unix crontab has 5 fields; minute, hour, day of month, month, day of week.

This line:

every '* * * * * *' do
       1 2 3 4 5 6 <- Error

You entered too many fields.

相关问答

更多
  • Unix crontab有5个字段 ; 分钟,小时,月,月,星期几。 这一行: every '* * * * * *' do 1 2 3 4 5 6 <- Error 你输入的字段太多了。 The Unix crontab has 5 fields; minute, hour, day of month, month, day of week. This line: every '* * * * * *' do 1 2 3 4 5 6 <- Error You entered ...
  • 如CentOS中的安装crontab所示,CentOS中的crontab软件包是vixie-cron 。 因此,请安装它: yum install vixie-cron 然后开始: service crond start 要使其持久化,以便在引导时启动,请使用: chkconfig crond on 在CentOS 7上,您需要使用cronie : yum install cronie 在CentOS 6上,您可以安装vixie-cron ,但真正的包是cronie : yum install vi ...
  • 首先确保您的脚本是可执行的: chmod u+x name_of_script 现在将其添加到crontab: crontab -e 还要确保您在crontab中编写完整路径,例如: */5 * * * * /home/user/loadcheck.sh First make sure your scripts are executable: chmod u+x name_of_script Now add it to crontab: crontab -e Also make sure you ...
  • 没有任何选项的命令crontab从stdin安装crontab。 如果需要附加到旧的crontab, crontab -l将返回当前的crontab。 The command crontab without any options installs a crontab from stdin. crontab -l returns the current crontab if you need to append to the old crontab.
  • 你缺少环境变量。 尝试这样的简单测试 将此添加到您的crontab * * * * * set > /tmp/vars 等待2-3分钟,返回并删除刚刚创建的crontab条目。 下一个, 从通常使用的shell命令行 set > myvars diff myvars /tmp/vars 这将向您展示环境的不同之处。 修改您的cron作业环境。 只需添加所需内容即可。 You are missing envrionment variables. Try a simple test like this a ...
  • 我终于能够通过两个步骤来解决这个问题了: 首先从virt-install命令中删除'console'相关配置。 在上面的命令中看到额外的参数。 把一些逻辑等待virt-install完成。 我在kickstart文件的安装后部分添加了shutdown,以便在完成所有软件包的安装后关闭VM。 然后在我的脚本中,我实际上“等待”VM进入关闭状态,然后再转到下一个命令。 这样我就可以在crontab中运行我的脚本。 它也与詹金斯一起工作。 希望这可以帮助面临同样问题的人。 I finally able to ca ...
  • 通常情况下,您使用crontab创建文件,并将其存储在机器的正确位置。 $ crontab < $HOME/etc/crontab 然后你使用crontab -l来列出它。 $ crontab -l # @(#)$Id: crontab,v 4.2 2007/09/17 02:41:00 jleffler Exp $ # Crontab file for Home Directory for Jonathan Leffler (JL) #------------------------------ ...
  • 根据crontab.guru , * * * * *和*\1 * * * *基本上是相同的,尽管您可能想尝试替代方案,以防万一您的系统不喜欢其中一个或另一个。 但是,在您发布的home.cron ,路径是错误的。 这个: * * * * * /users/username/desktop/forTrump/script.sh 应该: * * * * * /Users/username/Desktop/forTrump/script.sh 但是,如果脚本需要提升的权限,那么您将需要使用root cron ...
  • 正如在评论中通知的那样,问题是我使用了相对路径而不是绝对路径 As notified in a comment, problem was that I used relative path instead of an absolute path
  • 正如你在Python中想要的那样,你可以做这样的“事情”: import os; ... cur_cron = os.popen('crontab -l > current_crontab.txt'); cur_cron.read(); cur_cron.close(); fopen_cron = file('current_crontab.txt', 'a'); fopen_cron.write("\n### Comment here if you like"); fopen_cron.write("\n ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)