Mongodb works Javascript way. Every mongodb collection is a JSON object containing all kinds of Javascript objects such as boolean, arrays, objects and strings. In this example I am saving two different fields to my categories collection. searchableName – for…
Category: Mongodb
Export and Import Mongodb commands
To restore earlier database
1 | mongorestore -d dbname -c users C:/mypath/to/old/dbname |
To export a collection
1 | mongoexport --db envyd --collection categories --out users_remote.json |
To import a collection
1 | mongoimport --db envyd --collection posts --file posts.json |
To Update Single or Multiple records
1 2 3 4 5 | Update single db.users.update({}, {$set:{"email":'new_email_here'}}) Update multiple db.users.updateMany({}, {$set: {email: 'new_email_here'}}) |
To Query a collection for an array type field, by the length or array comparison
1 | { $where: "if (this.media && this.media.length > 1) {return this; } "} |
Query with…
How to get records filtered by a condition of another table field through join in Mongodb
I have two tables, posts and categories. In posts table there is a field categoryId. I want that only those posts are shown category of which is in enabled state, i.e. for which categories.enabled = true.