MongoDB can’t find data directory after upgrading to Mac OS 10.15 (Catalina)

This is the main error: exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating Catalina has a surprise change: it won’t allow changes to the root directory (this was discussed in a forum thread as well): % sudo mkdir -p /data/db mkdir: /data/db: Read-only file system Unfortunately, this is not spelled out explicitly in … Read more

MongoDB – paging

Using skip+limit is not a good way to do paging when performance is an issue, or with large collections; it will get slower and slower as you increase the page number. Using skip requires the server to walk though all the documents (or index values) from 0 to the offset (skip) value. It is much … Read more

Mongo, find through list of ids

After converting the strings into ObjectIds, you can use the $in operator to get the docs in the list. There isn’t any query notation to get the docs back in the order of your list, but see here for some ways to handle that. var ids = [‘512d5793abb900bf3e20d012’, ‘512d5793abb900bf3e20d011’]; var obj_ids = ids.map(function(id) { return … Read more

Mongorestore to a different database

You need to actually point at the “database name” container directory “within” the output directory from the previous dump: mongorestore -d db2 dumpdir/db1 And usually just <path> is fine as a positional argument rather than with -dir which would only be needed when “out of position” i.e “in the middle of the arguments list”. p.s. … Read more