When using arrays, you can add multiple conditions that must apply to the same element.

In the query db.items({list: {$elemMatch: {a: 1, b: "green"}}}), the condition is "a single array element of the list property must match a: 1 and b: "green"".

Read more

Aggregate Mongo queries accept multiple steps, including SQL-style joins using $lookup. This will add a new property to the results, with an array of documents from the other collection. You can then use $unwind to make each result map to a single document from the other collection. Finally, $project can help you select only the fields you care about.

Read more

You can't directly export an "aggregate" Mongo to CSV using the mongoexport command, as it's intended for simpler data exports. However, there is a way to output the results of one such query to a new collection, which you can then export.

Read more

You can find a document, update and return it using a single method: findAndModify. This is useful to deal with concurrency issues when multiple clients are trying to process documents from a collection and you don't want two of them processing the same one.

Read more

Object IDs in Mongo store several variables (screenshot from MongoChef), including the time it was created, a machine identifier, a process ID and an internal counter.

Screenshot showing an object ID and its parsed values

Read more
Subscribe to MongoDB
Mastodon Mastodon