Skip to main content

Collections

1. Mongodb

MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on concept of collection and document.

1.1 Structure

Database

Database is a physical container for collections. Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases.

Collection

Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema. Documents within a collection can have different fields. Typically, all documents in a collection are of similar or related purpose.

Document

A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection's documents may hold different types of data.

Sample Document:

{
_id: ObjectId(7df78ad8902c)
title: 'MongoDB Overview',
description: 'MongoDB is no sql database',
by: 'tutorials point',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 100,
comments: [
{
user:'user1',
message: 'My first comment',
dateCreated: new Date(2011,1,20,2,15),
like: 0
},
{
user:'user2',
message: 'My second comments',
dateCreated: new Date(2011,1,25,7,45),
like: 5
}
]
}

_id is a 12 bytes hexadecimal number which assures the uniqueness of every document. You can provide _id while inserting the document. If you don’t provide then MongoDB provides a unique id for every document. These 12 bytes first 4 bytes for the current timestamp, next 3 bytes for machine id, next 2 bytes for process id of MongoDB server and remaining 3 bytes are simple incremental VALUE.

1.2 Reference from Mongo

  1. Query and Projection Operators: Query operators provide ways to locate data within the database and projection operators modify how data is presented. For more information information please check Mongodb documentation.
  2. Update Operators: Update operators are operators that enable you to modify the data in your database or add additional data. For more information information please check Mongodb documentation.
  3. Aggregation Pipeline Stages: Available aggregation stages for Aggregation Pipeline. For more information information please check Mongodb documentation.
  4. Aggregation Pipeline Operators: Aggregation pipeline operations have a collection of operators available to define and manipulate documents in pipeline stages. For more information information please check Mongodb documentation.

2. Create a Mongo Collection

SoftyFlow give you the ability to create a collection in easy way by selecting the collection tab and give a name to your DB.

Create collection screenshot

3. Operations

CRUD operations in MongoDB target a single collection, not multiple collections.

3.1. Create an object

Insert operations in MongoDB are atomic on a single document level. MongoDB provides two different create operations that you can use to insert documents into a collection:

  • InsertOne In SoftyFlow: You can insert one document in your collection in user form and process by following the steps already mentioned in action the difference is in process, you should first create an input/output variable then choose an action.
  • InsertMany In SoftyFlow: You can insert multiple documents in your collection in user form and process by creating a script and follow the steps already mentioned in insertMany web modeler for user form and insertMany for process, the difference is in process, you should first create an input/output variable then choose script as type of this variable.

3.2. Read an object

Read operations allow you to provide special query filters and criteria for specifying what documents you want. Find out more about the available query filters in the MongoDB documentation. Query modifiers may also be used to change how many results are returned. There are two ways to read documents in a collection:

  • Find In SoftyFlow: You can get multiple documents in your collection in user form and process by following the steps already mentioned in action the difference is in process, you should first create an input/output variable then choose an action.
  • FindOne In SoftyFlow: You can get one document in your collection in user form and process by following the steps already mentioned in action the difference is in process, you should first create an input/output variable then choose an action.

3.3. Update an object

Like create operations, update operations operate on a single collection, and they are atomic at a single document level. An update operation takes filters and criteria to select the documents you want to update. You should be careful when updating documents, as updates are permanent and can’t be rolled back. This applies to delete operations as well. For MongoDB CRUD, there are three different methods of updating documents:

  • UpdateOne In SoftyFlow: You can update one document in your collection in user form and process by following the steps already mentioned in action the difference is in process, you should first create an input/output variable then choose an action.
  • UpdateMany In SoftyFlow: You can update multiple documents in your collection in user form and process by creating a script and follow the steps already mentioned in update web modeler for user form and update for process, the difference is in process, you should first create an input/output variable then choose script as type of this variable.
  • ReplaceOne.

3.4. Delete an object

Delete operations operate on a single collection, like update and create operations. Delete operations are also atomic for a single document. You can provide delete operations with filters and criteria in order to specify which documents you would like to delete from a collection. The filter options rely on the same syntax that read operations utilize. MongoDB has two different methods of deleting records from a collection:

  • DeleteOne In SoftyFlow: You can delete one document from your collection in user form and process by following the steps already mentioned in action the difference is in process, you should first create an input/output variable then choose an action.
  • DeleteMany In SoftyFlow: You can delete multiple document from your collection in process by following the steps already mentioned in delete you should first create an input/output variable then choose script as type of this variable.