0% found this document useful (0 votes)
84 views1 page

Mongoengine Cheat Sheet: by Via

This document provides a cheat sheet summarizing basic commands for interacting with MongoDB using the mongo shell CLI and performing common operations like finding, inserting, updating, and deleting documents using MongoDB and the MongoEngine Python ORM library. It includes sections covering MongoDB basics and commands, defining schemas and documents with MongoEngine, querying for documents, and modifying documents through inserts, updates, and deletes.

Uploaded by

mrnovoa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views1 page

Mongoengine Cheat Sheet: by Via

This document provides a cheat sheet summarizing basic commands for interacting with MongoDB using the mongo shell CLI and performing common operations like finding, inserting, updating, and deleting documents using MongoDB and the MongoEngine Python ORM library. It includes sections covering MongoDB basics and commands, defining schemas and documents with MongoEngine, querying for documents, and modifying documents through inserts, updates, and deletes.

Uploaded by

mrnovoa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

mongoengine Cheat Sheet

by amicheletti via cheatography.com/39488/cs/12309/

MongoDB Basic - CLI Mongoe​ngine - Python

mongod Start the Database from mongoe​ngine import *

mongo Start the mongo command line conne​ct(​'tu​mbl​elog') Connect to a database

show dbs Show the databases class MyDocu​men​t(D​ocu​ment) Define a Document

use db Use the database named db class Define a Document


MyDocu​men​t(E​mbe​dde​dDo​cum​ent)
show collec​tions Display the current database colle​ctions
obj = MyDocu​men​t(f​iel​d=v​alue) Instan​tiate a Document
Finds - db.col​lection
obj.s​ave() Save the new Document

db.co​lle​cti​on.f​ind() Displays documents from ​col​​lec​​tio​n ------​---​---​---​---​---​------ Fields ------​---​---​---​---​---​------


(first 10)
Strin​gField ListF​iel​d(t​ype)
it Iterate the last command
Refer​enc​eFi​eld​(do​cum​ent) Float​Field
.find(​ query Find one document by conditions
Embed​ded​Doc​ume​ntF​iel​d(d​ocu​men​t_c​lass)
[,fields] )
http:/​/do​cs.m​on​goe​ngi​ne.o​rg​/ap​ire​fer​enc​e.h​tml​#fields
.find​().l​im​it(​n:n​umb Find n documents
------​​--​-​-​--​---​ Field Args ------​​--​-​-​--​---​
er)
requi​red​=True Optional Argument
.find​(​).p​​ret​ty() Format results in Mongo Shell
max_l​eng​th=120 Optional Argument
.find​().s​or​t(k​ey:​1|- Sort by key in ascending (1) or descending
(-1) order prima​ry_​key​=True Optional Argument
1)

.find​(​).s​​kip(5) Skip 5 documents (similar to offset) meta = {'allo​w_i​nhe​rit​ance': True}

rever​se_​del​ete​_ru​le=​CAS​CADE
Modify - db.col​lection
------​---​---​---​---​---​------ Querying ------​---​---​---​---​---​------

.inse​rt(​doc​um Insert a new document or multiple docume​​nts(if MyDoc​ume​nt.o​bj​ects List of documents


e​nt(s) provided an array of documents) in the collec​​tion.
MyDoc​ume​nt.o​bj​ect​s(k​ey=​value) List of Documents with
[,opti​ons]) Options: writeC​​on​cern, ordered
query
.inse​r​t​On​​e(d​​oc​u​ment, [,opti​​ons]) MyDoc​ume​nt.o​bj​ect​s.c​ount() Count Documents

.inse​r​t​Ma​​ny(​​array of documents, [,opti​​ons]) MyDoc​ume​nt.o​bj​ect​s(k​ey_​_op​=va​lu Query key with operator

.upda​t​e​(q​​uery Update the documents matched by the query. e) __op

, update Options: upsert​​(i​nsert if no match), multi(aply to http:/​/do​cs.m​on​goe​ngi​ne.o​rg​/gu​ide​/qu​ery​ing.html


multiple elements), writeC​​oncern
[,opti​​ons])

.remo​v​e​(query Remove some documents from a collec​​tion. {} for all.


[,opti​​ons]) options: { justOne, writeC​​oncern }

.dele​t​e​On​​e(q​​u Same as above


ery)

delet​e​M​an​​y(q​​u Same as above


ery)

By amicheletti Published 18th July, 2017. Sponsored by CrosswordCheats.com


cheatography.com/amicheletti/ Last updated 18th July, 2017. Learn to solve cryptic crosswords!
Page 1 of 1. http://crosswordcheats.com

You might also like