don't manipulate documents being updated by default

This commit is contained in:
Mike Dirolf 2009-04-15 10:43:17 -04:00
parent 96caf793a3
commit a4b642b7ab
2 changed files with 11 additions and 1 deletions

View File

@ -176,7 +176,7 @@ class Collection(object):
return len(docs) == 1 and docs[0] or docs
def update(self, spec, document, upsert=False, manipulate=True, safe=False):
def update(self, spec, document, upsert=False, manipulate=False, safe=False):
"""Update an object(s) in this collection.
Raises TypeError if either spec or document isn't an instance of

View File

@ -273,6 +273,16 @@ class TestCollection(unittest.TestCase):
self.assertEqual(db.test.find_one(id1)["x"], 7)
self.assertEqual(db.test.find_one(id2)["x"], 1)
def test_upsert(self):
db = self.db
db.drop_collection("test")
db.test.update({"page": "/"}, {"$inc": {"count": 1}}, upsert=True)
db.test.update({"page": "/"}, {"$inc": {"count": 1}}, upsert=True)
self.assertEqual(1, db.test.count())
self.assertEqual(2, db.test.find_one()["count"])
def test_safe_update(self):
db = self.db
db.drop_collection("test")