0

I have a simple sample database which I use to develop a simple micro framework for our application. To verify versioning works as expected, I need to update all documents by adding a new field. I used this thread as guide, so what I'm doing should work.

{
  "_id": {
    "$oid": "63d95015f94d9a88ecbc1a00"
  },
  "Version": 1,
  "bookTitle": "Fancy Book 0",
  "author": "Author 0"
}
{
  "_id": {
    "$oid": "63d95015f94d9a88ecbc1a01"
  },
  "Version": 1,
  "bookTitle": "Fancy Book 1",
  "author": "Author 1"
}
... 8 more

Now when I run this in MongoSH:

db.Books.updateMany({}, {$set: {'NewField': true}})

I get this output:

{
  acknowledged: true,
  insertedId: null,
  matchedCount: 0,
  modifiedCount: 0,
  upsertedCount: 0
}

So what's the issue here? It does execute and it seemingly is correct, but no single document updates. The official documentation states that {} is a selector for all documents, so why does it not match even one of them?

SharpShade
  • 1,761
  • 2
  • 32
  • 45
  • The query looks OK. Are you sure this is the name of your DB? – nimrod serok Feb 01 '23 at 09:28
  • Well I have a database called `Test` which I use in MongoDB Compass. The collection is called `Books` so everything should be fine... – SharpShade Feb 01 '23 at 09:32
  • The problem was that both MongoDB Compass and DataGrip by default run the shell with lower-case database name `test` but database names are case-sensitive. So switching to the right database with `use Test` fixes this. Not really user-friendly though that you can execute a command against a non-existing database without failure... – SharpShade Feb 02 '23 at 13:05

0 Answers0