0

I have a collection containing Reddit comments, gathered by a bot. The schema looks like this:

{
    _id: ObjectId,
    author: string,
    body: string,
    permalink: string,
    created_utc: number,
    upvotes: number,
    downvotes: number
}

I would like to remove the upvotes and downvotes fields. I have tried using the following updateMany query:

use DBname

db.comments.updateMany({}, {$unset: {upvotes: "", downvotes: ""}})

Running this, I get the following error:

MongoServerError: Executing this update would put you over your space quota

This data base is located on MongoDB Atlas, in a free instance (limited at 512 MB). However I'm currently only using around 255 MB. I would expect this query to free up space, not to occupy more.

I should mention that these parameters do work with db.updateOne(), however I would like to run the query using a single operation, rather than writing a script and calling multiple updateOne()s.

ornato_t
  • 15
  • 5
  • 1
    MongoDB will create a copy of current DB, without content on those two. But before doing so, it doesn't know how much space that copy will occupy. So, it checks that if rest of free space can handle copy of that current DB + some overhead... – JJussi Nov 04 '22 at 10:30
  • @JJussi does this imply that I can't do any kind of updateMany query if I'm over 50% of my DB's capacity? – ornato_t Nov 04 '22 at 11:13
  • This looks like a good question for their developer forum - https://www.mongodb.com/community/forums/ – user20042973 Nov 04 '22 at 18:21
  • 1
    Not necessary "any kind of updateMany"... If you can do it using indexes. i.e. you get result set (what you update) from index. Only when system don't know all rows what it should update, it must go thru whole database. One solutions would be using cursor.forEach(). So you make cursor what is whole DB and then "update" (inside of that loop) row by row. Of course it's "slow" compare of updateMany-whole-db approach. – JJussi Nov 05 '22 at 12:17

0 Answers0