Export all collection documents in
#mongodb #export #mongoexport #mongodump #collection #database
MongoDB
to a JSON
file:mongoexport --db YOUR_DATABASE --collection YOUR_COLLECTION_NAME --out YOUR_OUTPUT_FILE_NAME.json
NOTE:
do not use this command for full database backup! Use mongodump
instead#mongodb #export #mongoexport #mongodump #collection #database
What is
Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.
Circular buffers are filled and emptied, so capped collection has similar behaviours.
Some notes:
- Automatic Removal of Oldest Documents
- Capped collections have an
- You cannot delete documents from a capped collection. To remove all documents from a collection, use the drop() method to drop the collection and recreate the capped collection.
- You cannot shard a capped collection.
- You must create capped collections explicitly
To create a capped collection:
The name of the collection in our example is
You can also specify maximum number of documents for the collection using
Check whether collection is capped or not:
Convert a non-capped collection to capped:
#mongodb #mongo #capped #collection #capped_collection
Capped Collections
in MongoDB
?Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.
Circular buffers are filled and emptied, so capped collection has similar behaviours.
Some notes:
- Automatic Removal of Oldest Documents
- Capped collections have an
_id
field and an index on the _id
field by default.- You cannot delete documents from a capped collection. To remove all documents from a collection, use the drop() method to drop the collection and recreate the capped collection.
- You cannot shard a capped collection.
- You must create capped collections explicitly
To create a capped collection:
db.createCollection( "cpu_metrics", { capped: true, size: 100000 } )
The name of the collection in our example is
cpu_metrics
with the flag of capped=true
and size of the collection.You can also specify maximum number of documents for the collection using
max
as following example:db.createCollection("cpu_metrics", { capped : true, size : 5242880, max : 5000 } )
NOTE:
the size
argument is always required, even when you specify max number of documents.Check whether collection is capped or not:
db.collection.isCapped()
Convert a non-capped collection to capped:
db.runCommand({"convertToCapped": "mycoll", size: 100000});
#mongodb #mongo #capped #collection #capped_collection
MongoDB data types
String:
You know what it is!Integer
: This type is used to store a numerical value. Integer can be 32 bit or 64 bit depending upon your server.Boolean
: True/FalseDouble
: This type is used to store floating point values.Arrays
: [list, of, elements]Timestamp
: This can be handy for recording when a document has been modified or added.Object
: This datatype is used for embedded documents. Like {"images": {"a": "ali", "b": "reza"}}Null
: This type is used to store a Null value.Date
: This datatype is used to store the current date or time in UNIX time format. You can specify your own date time by creating object of Date and passing day, month, year into it.Object ID
: This datatype is used to store the document’s ID.There are some more like
Code
, Regex
and so which is used less than other data types.#mongodb #data_type #mongo #database #collection #object
https://www.thoughtworks.com/insights/blog/rest-api-design-resource-modeling
#RESTAPI #REST #API #collection #resource #CQRS #CRUD #URI #URN #REST_API
#RESTAPI #REST #API #collection #resource #CQRS #CRUD #URI #URN #REST_API
Thoughtworks
REST API Design - Resource Modeling
“The key abstraction of information in REST is a resource. Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a…