mongodb无法将$ pull/$ pullAll修饰符应用于非数组,如何删除数组元素 [英] mongodb Cannot apply $pull/$pullAll modifier to non-array, How to remove array element

查看:88
本文介绍了mongodb无法将$ pull/$ pullAll修饰符应用于非数组,如何删除数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了有关mongodb的问题.

i met a problem about mongodb.

db.tt.find()
{ "_id" : ObjectId("513c971be4b1f9d71bc8c769"), 
  "name" : "a", 
  "comments" : [ { "name" : "2" }, { "name" : "3" } ] 
}

上面是测试文档.

我想提取comment.name = 2

i want to pull comments.name = 2

我愿意

db.tt.update({'comments.name':'2'},{'$pull':{'comments.$.name':'2'}});

但是控制台会显示以下消息:

but the console print these message:

无法将$ pull/$ pullAll修饰符应用于非数组

Cannot apply $pull/$pullAll modifier to non-array

我的mongodb版本是2.0.6

my mongodb version is 2.0.6

谁可以帮助我?非常感谢

who can help me? Thank you very much

推荐答案

您的$pull语法已关闭,应该为:

Your $pull syntax is off, it should be:

db.tt.update({'comments.name': '2'}, {$pull: {comments: {name: '2'}}})

这篇关于mongodb无法将$ pull/$ pullAll修饰符应用于非数组,如何删除数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆