0

I want to search and update any document which matches a particular id but dont want to specify any specific collection but the search needs to query all the documents in a particular database.

kind of db.find() not db.collection.find();

Any command which I may have overlooked in mongoose that accomplishes this?

Community
  • 1
  • 1
digster
  • 392
  • 5
  • 20
  • You really should consider having a single collection of all `id`s that maps an `id` to a collection. Or consider using an `id` that contains a collection identifier embedded in the `id`. – WiredPrairie May 25 '13 at 12:01
  • Note that different documents with the same _id can be in multiple collections. – Philipp May 28 '13 at 08:36

1 Answers1

1

There is no such thing as a db.find(). _id's are only unique in a specific collection. You can have different documents with different content but the same _id in different collections.

But what you can do is get a list of all collections using db.getCollectionNames() and query each of them.

By the way: I don't know what you are trying to achieve, but it really smells to me. Collections should be used to group objects which belong into a specific context. When you don't know the collection of an object you are searching for, you likely are doing something wrong.

Philipp
  • 67,764
  • 9
  • 118
  • 153