Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9303169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:25:22+00:00 2026-06-18T23:25:22+00:00

I am working on pymongo and this is my document: { _id: ObjectId(51211b57f07ddaa377000000), assignments:

  • 0

I am working on pymongo and this is my document:

{
   "_id": ObjectId("51211b57f07ddaa377000000"),
   "assignments": {
     "0": {
       "0": {
         "_id": ObjectId("5120dd7400a4453d58a0d0ec") 
      },
       "1": {
         "_id": ObjectId("5120dd8e00a4453d58a0d0ed") 
      },
       "2": {
         "_id": ObjectId("5120ddad00a4453d58a0d0ee") 
      } 
    } 
  },
   "password": "my_passwd",
   "username": "john" 
}

I would like to unset the “assignment” property of all such docs.
I was able to achieve this on the mongo shell by doing:

db.users.update({}, {$unset: {"assignments": 1}}, false, true)

i.e., I passed the upsert and multi flag as the last two parameters to the update function function on users collection.
However I did this with pymongo:

db.users.update({}, {"$unset": {"assignments": 1}}, False, True)

But the python interpreter threw an error as follows:

File "notes/assignment.py", line 34, in <module>
    db.users.update({}, {"$unset": {"assignments": 1}}, False, True)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 481, in update
    check_keys, self.__uuid_subtype), safe)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 852, in _send_message
    rv = self.__check_response_to_last_error(response)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 795, in __check_response_to_last_error
    raise OperationFailure(details["err"], details["code"])
pymongo.errors.OperationFailure: Modifiers and non-modifiers cannot be mixed

Where am I going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T23:25:24+00:00Added an answer on June 18, 2026 at 11:25 pm

    The problem is that the two flags you are passing in aren’t upsert and multi. Based on the documentation of PyMongo’s Collection.update (found here), it looks like you might be passing in values for the upsert and manipulate options, although I am not certain.

    All you have to do to solve this is use one of Python’s most awesome features: named arguments. By specifying which options you are passing to update, you add clarity to your code in addition to making sure accidents like this don’t happen.

    In this case, we want to pass the options upsert=False and multi=True.

    db.users.update({}, { "$unset": { "assignments": 1 } }, upsert=False, multi=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with H2 I get this error when I try to write a row
working on this site: http://thegoodgood.com/gus_2 responsive queries are working in browser but when i
Working through more book examples- this one is a partial poker program- This segment
Working on this question, I found an inconsistent behavior. Why reference binding behave different
I'm learning Django REST Framework and working on this example; http://django-rest-framework.org/examples/blogpost.html but I'm getting
Working on an existing webapp (PHP/MySQL) I came to this point: I have 2
Working Example: This is almost identical to code I use in another places on
I'm working on creating scripts using python, mongodb and the pymongo module to fetch
Working on a project, I have this issue where my array slicetable returns undefined
WORKING: This is my working rich:listShuttle when sourceValue and target value are List of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.