Author: admin
-
MongoDB Data API
MongoDB Data API The MongoDB Data API can be used to query and update data in a MongoDB database without the need for language specific drivers. Language drivers should be used when possible, but the MongoDB Data API comes in handy when drivers are not available or drivers are overkill for the application. Read & Write with…
-
MongoDB Schema Validation
Schema Validation By default MongoDB has a flexible schema. This means that there is no strict schema validation set up initially. Schema validation rules can be created in order to ensure that all documents a collection share a similar structure. Schema Validation MongoDB supports JSON Schema validation. The $jsonSchema operator allows us to define our document structure. Example This…
-
Indexing & Search
Indexing & Search MongoDB Atlas comes with a full-text search engine that can be used to search for documents in a collection. Atlas Search is powered by Apache Lucene. Creating an Index We’ll use the Atlas dashboard to create an index on the “sample_mflix” database from the sample data that we loaded in the Intro to Aggregations section.…
-
MongoDB Aggregation Pipelines
Aggregation Pipelines Aggregation operations allow you to group, sort, perform calculations, analyze data, and much more. Aggregation pipelines can have one or more “stages”. The order of these stages are important. Each stage acts upon the results of the previous stage. Example Sample Data To demonstrate the use of stages in a aggregation pipeline, we…
-
MongoDB Update Operators
MongoDB Update Operators There are many update operators that can be used during document updates. Fields The following operators can be used to update fields: Array The following operators assist with updating arrays.
-
MongoDB Query Operators
MongoDB Query Operators There are many query operators that can be used to compare and reference document fields. Comparison The following operators can be used in queries to compare values: Logical The following operators can logically compare multiple queries. Evaluation The following operators assist in evaluating documents.
-
MongoDB mongosh Delete
Delete Documents We can delete documents by using the methods deleteOne() or deleteMany(). These methods accept a query object. The matching documents will be deleted. deleteOne() The deleteOne() method will delete the first document that matches the query provided. Example deleteMany() The deleteMany() method will delete all documents that match the query provided. Example
-
MongoDB mongosh Update
Update Document To update an existing document we can use the updateOne() or updateMany() methods. The first parameter is a query object to define which document or documents should be updated. The second parameter is an object defining the updated data. updateOne() The updateOne() method will update the first document that is found matching the provided query. Let’s see what the…
-
MongoDB mongosh Find
Find Data There are 2 methods to find and select data from a MongoDB collection, find() and findOne(). find() To select data from a collection in MongoDB, we can use the find() method. This method accepts a query object. If left empty, all documents will be returned. Example findOne() To select only one document, we can use the findOne() method. This method…
-
MongoDB mongosh Insert
Insert Documents There are 2 methods to insert documents into a MongoDB database. insertOne() To insert a single document, use the insertOne() method. This method inserts a single object into the database. Note: When typing in the shell, after opening an object with curly braces “{” you can press enter to start a new line in the editor…