🎩
wilmerags 🌱
  • Home
  • Social
  • Cloud
    • Aws
  • Stats
  • Code
    • Scrum
    • Ssh
    • Vim
    • Dvc
    • Postgresql
    • Tmux
    • Terraform
    • Web tools
    • Sql
    • Rest api
    • Mongo
    • Docker
    • Octave
    • Elasticsearch
    • Kubernetes
    • Bash
    • Rabbitmq
    • Databases
      • Mongo
      • Elasticsearch
      • Sql
        • Postgresql
    • Devops
      • Terraform
      • Docker
      • Kubernetes
      • Rabbitmq
    • Python
      • Airflow
      • Keras
      • Spark
      • Azure
      • Matplotlib
      • Jupyter
      • Numpy
      • Databases
      • Sklearn
      • Requests
      • Pandas
      • Elasticsearch
      • Tensorflow
    • Git
      • Gitflow
    • R
      • Lpsolve
  • Indie-hacker
  • Macos
  • Interesting
  • Thoughts
    • Health
    • Work
    • Relationships
    • On the need of expressiveness
    • On organizing knowledge
    • On the importance of questions
  • Linux
    • Vim
    • Tmux
  • Webdev
    • Vue
  • Readings
    • Psychology
    • Habits
    • Projects management
    • Quotes
    • Dopamine detox
  • Ai
    • Ml
      • Xgboost
      • Performance evaluation
      • Community detection
      • Cloud_platforms
        • Ai platform
        • Sagemaker
      • Unsupervised_learning
    • Nlp
    • DS
Powered by GitBook
On this page
  1. Code
  2. Databases

Mongo

Frecuently used code for mongo

PreviousDatabasesNextElasticsearch

Last updated 3 years ago

Was this helpful?

CtrlK
  • Python utils
  • Useful tools

Was this helpful?

Export database:

mongodump --host <database-host> -d <database-name> --port <database-port> --out directory

Import database:

mongorestore --host <database-host> -d <database-name> --port <database-port> foldername

uri is also an option:

mongorestore --uri="uri" --dir="dir"

Search by regex

db.collectionname.find({"name": {'$regex':'^File'}})
# All the documents that start with File

Update field for a existing document

# Example
db.agents.find().forEach((doc) => {  doc.tags[0] = doc.tags[0].replace(">", "-"); db.agents.save(doc); });

Python utils

count records

collection.count_documents(query_string)

Make sure update was done

try:
    result = self.settings_store.admin_users.update_one(user_query, language_insert)
    return result.matched_count > 0
except errors.PyMongoError as e:
    return False

Useful tools

  • restheart