B4J Programming Press on the image to return to the main documentation page.

jMongoDB

List of types:

MongoClient
MongoCollection
MongoDatabase
UpdateResult

MongoClient

A MongoDB client. Implemented as a connection pool. A single instance can be used by multiple handlers.
MongoDB manual

Events:

None

Members:


  Close

  DatabaseNames As List [read only]

  DateToTicks (Date As Object) As Long

  GetDatabase (DatabaseName As String) As MongoDatabase

  Initialize (EventName As String, ConnectionString As String)

  IsInitialized As Boolean

  StringToObjectId (Id As String) As Object

  TicksToDate (Ticks As Long) As Object

Members description:

Close
Closes the client.
DatabaseNames As List [read only]
Lists the database names.
DateToTicks (Date As Object) As Long
Utility method that converts a native Date object to ticks.
GetDatabase (DatabaseName As String) As MongoDatabase
Returns a MongoDatabase. Creates the database if it does not already exist.
Initialize (EventName As String, ConnectionString As String)
Initializes the client and sets the connection Uri.
EventName - Currently not used.
ConnectionString - Connection Uri.
Example:
mongo.Initialize("", "mongodb://127.0.0.1:27017")
IsInitialized As Boolean
StringToObjectId (Id As String) As Object
Utility method that converts a 24 byte hex string to an object id.
Can be used to find documents based on the id.
TicksToDate (Ticks As Long) As Object
Utility method that converts ticks to a native Date object.

MongoCollection

Represents a single collection.

Events:

None

Members:


  Aggregate (Pipeline As List) As List

  Count As Long [read only]

  CreateIndex (Keys As Map) As String

  Delete (Filter As Map) As Long

  Drop

  Find (Filter As Map, Projection As List, Sort As Map) As List

  Find2 (Filter As Map, Projection As List, Sort As Map, Skip As Int, Limit As Int) As List

  Insert (Documents As List)

  IsInitialized As Boolean

  Replace (Filter As Map, Document As Map, Upsert As Boolean) As UpdateResult

  Update (Filter As Map, Update As Map) As UpdateResult

Members description:

Aggregate (Pipeline As List) As List
Executes an aggregation pipeline. Each element in the list is a Map that defines a single step.
Count As Long [read only]
Gets the number of documents in the collection.
CreateIndex (Keys As Map) As String
Creates an index. Returns the index name.
Example:
Collection.CreateIndex(CreateMap("rank": 1))
Delete (Filter As Map) As Long
Deletes the documents matching the filter. Returns the number of documents deleted.
Drop
Deletes the collection.
Find (Filter As Map, Projection As List, Sort As Map) As List
Finds matching documents in the collection.
Filter - A Map with the filter.
Projection - List with the field names that should be returned. Pass Null to return all fields.
Sort - The sort map. Pass Null if not needed.

Example:
Dim res As List = Collection.Find(CreateMap("status": "good"), Null, CreateMap("score": 1))
Find2 (Filter As Map, Projection As List, Sort As Map, Skip As Int, Limit As Int) As List
Similar to Find
Skip - Number of documents to skip.
Limit - Maximum number of documents to return.
Insert (Documents As List)
Inserts one or more documents.
Example: Collection.Insert(Array(CreateMap("key1": 100, "key2": 200)))
IsInitialized As Boolean
Replace (Filter As Map, Document As Map, Upsert As Boolean) As UpdateResult
Replaces the first matching document.
Filter - The filter map.
Document - New document.
Upsert - If true then the document will be inserted if there is no match.
Update (Filter As Map, Update As Map) As UpdateResult
Updates matching documents.
Filter - The filter map.
Update - Update operations.

Example:
Collection.Update(CreateMap("_id": "some_id"), CreateMap("$set": CreateMap("score": 3)))

MongoDatabase

Provides access to a database.

Events:

None

Members:


  CollectionNames As List [read only]

  Drop

  GetCollection (CollectionName As String) As MongoCollection

  IsInitialized As Boolean

  Name As String [read only]

  RunCommand (Command As Map) As Map

Members description:

CollectionNames As List [read only]
Lists the collections names.
Drop
Deletes the database.
GetCollection (CollectionName As String) As MongoCollection
Returns a MongoCollection. Creates the collection if it does not already exist.
IsInitialized As Boolean
Name As String [read only]
Gets the database name.
RunCommand (Command As Map) As Map
Runs a database command.

UpdateResult


Events:

None

Members:


  IsInitialized As Boolean

  MatchedCount As Long [read only]

  ModifiedCount As Long [read only]

Members description:

IsInitialized As Boolean
MatchedCount As Long [read only]
ModifiedCount As Long [read only]

Top