Note that there are some explanatory texts on larger screens.

plurals
  1. POpymongo justOne & multi
    primarykey
    data
    text
    <p>I have a database "testdb" with collection "testcol" which looks like this:</p> <pre><code>{u'_id': ObjectId('50eeb8029b75941b9af614bd'), u'birth': 1} {u'_id': ObjectId('50eeb82e9b75941bc820f22c'), u'birth': 2} {u'_id': ObjectId('50eeb82e9b75941bc820f22d'), u'birth': 3} {u'_id': ObjectId('50eeb82f9b75941bce96032c'), u'birth': 2} {u'_id': ObjectId('50eeb82f9b75941bce96032d'), u'birth': 3} </code></pre> <p>The code is like:</p> <pre><code>m_connection = MongoClient(M.HOST,M.PORT) col = m_connection['testdb']['testcol'] #some_operation cursor = col.find() for doc in cursor: print doc </code></pre> <p>Im trying to update all the documents with birth higher than one, so I replace some_operation with <code>col.update({'birth':{'$gt':1}},{'$set':{'death':'near'}},{'multi':True})</code> I get the error: <code>TypeError: upsert must be an instance of bool</code></p> <p>Similarly, I want to delete only one out of all the documents that have birth as 2 0r 3.<br> I replace some_operation with <code>col.remove({'birth' : {'$in' : [2,3]}},{'justOne' : 1})</code> I get the error: <code>TypeError: Wrong type for safe, value must be a boolean</code></p> <p>I tried using direct booleans in place of {} array, but only one document is update and all those with birth as 2 or 3 are deleted. </p> <p>Just in case it has something to do with versions: I have pymongo-2.4.1 and Python2.7 Any clues where im going wrong?? Thanks a lot.</p> <p>Edit: The documentation says: update(spec, document[, upsert=False[, manipulate=False[, safe=None[, multi=False[, check_keys=True[, **kwargs]]]]]])</p> <p>Does it mean that: if i want to use 'multi'=True, i have to compulsarily go around defining values for whatever (upsert, manipulate, safe) comes before it?</p> <p>Also, for remove, it says: remove([spec_or_id=None[, safe=None[, **kwargs]]]) Where is the 'justOne' mentioned <a href="http://docs.mongodb.org/manual/applications/delete/" rel="nofollow">here</a>??</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload