Skip to content

Commit 132fae4

Browse files
committed
新增mongo数组字段的操作
1 parent 02aa310 commit 132fae4

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

test/test_mongo.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'sex': 'F',
2323
'age': 20,
2424
'city': 'shanghai',
25+
'skill': ['word', 'excel']
2526
},
2627
{
2728
'_id': 2,
@@ -30,6 +31,7 @@
3031
'sex': 'M',
3132
'age': 22,
3233
'city': 'shanghai',
34+
'skill': ['php', 'java']
3335
},
3436
{
3537
'_id': 3,
@@ -38,6 +40,7 @@
3840
'sex': 'M',
3941
'age': 22,
4042
'city': 'beijing',
43+
'skill': ['php', 'python']
4144
}
4245
]
4346

@@ -56,6 +59,11 @@ def test():
5659
conn.output_rows(table_name)
5760
print conn.update(table_name, {}, {'age': 1}, 'inc') # 所有记录年龄增加1岁
5861
conn.output_rows(table_name)
62+
# print conn.update(table_name, {'id': 3}, {'skill': 'mysql'}, 'push') # 向数组字段中添加单个元素
63+
# print conn.update(table_name, {'id': 3}, {'skill': 'mysql'}, 'pull') # 向数组字段中删除单个元素
64+
print conn.update(table_name, {'id': 3}, {'skill': ['ruby', 'c#']}, 'pushAll') # 向数组字段中添加多个元素
65+
print conn.update(table_name, {'id': 3}, {'skill': ['ruby', 'c#']}, 'pullAll') # 向数组字段中删除多个元素
66+
conn.output_rows(table_name)
5967
except Exception, e:
6068
print e
6169

0 commit comments

Comments
 (0)