2013-07-16 79 views
2

我有这样插入项目的MongoDB文档中

{ "_id" : "decfed9a04b997d", "pushed_list" : [ ] } 

的文件,我想更新/被存储在一个Python列表

lis1 = 
    [ 
     { 
     item : 'item1', 
     desc : 'desc_item1' 
     }, 
     { 
     item : 'item2', 
     desc : 'desc_item2' 
     }, 
     { ........................ 
     } 

    ] 

我这些子项插入“pushed_list”试过这个

db.monitor.update({'_id' : 'dbjkdd'}, { '$push':{'pushed_list': {'$each':{lis1}}}}) 

它给了我一个错误。

Traceback (most recent call last): 
    File "monitor.py", line 13, in <module> 
    db.monitor.update({'_id' : 'dbjfdd'}, { '$push':{'pushed_list': {'$each':{lis1}}}}) 
TypeError: unhashable type: 'list' 

回答

6

我找到了答案,在我这边很愚蠢;只需要删除多余的括号{}

而是这个

db.monitor.update({'_id' : 'dbjkdd'}, { '$push':{'pushed_list': {'$each':{lis1}}}}) 

。使用本

db.monitor.update({'_id' : 'dbjkdd'}, { '$push':{'pushed_list': {'$each':lis1}}}) 

即删除'{''$each'后,其对应的'}'

+0

的NoSQL数据块只是简单SOOOO – Sam