MongoDB.OpenCollection
----------------------

Sets the current collection.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [MongoDB](component_MongoDB.md) | [12.3](newinversion123.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "MongoDB.OpenCollection"; MongoDBRef; Name ) 

**MBS**( **"MongoDB.OpenCollection";** /\* Sets the current collection. \*/  
**$MongoDBRef**; /\* The reference number for the mongo connection.e.g. $MongoDB \*/   
**$Name**) /\* The collection name to use.e.g. "test" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| MongoDBRef | The reference number for the mongo connection. | $MongoDB |
| Name | The collection name to use. | "test" |

### Result

Returns OK or error.

### Description

Sets the current collection.  
### Examples

Open collection:

 Set Variable \[ $r ; Value: MBS ( "MongoDB.OpenCollection"; $Mongo ; test::Collection Name ) \]   
If \[ MBS ("IsError") \]   
 Set Variable \[ $x ; Value: MBS ( "[MongoDB.Release](MongoDBRelease.md)"; $Mongo ) \]   
 Show Custom Dialog \[ "Failed to open collection." ; $r \]   
 Exit Script \[ Text Result: \]   
End If  
### See also

- [MongoDB.CollectionName](MongoDBCollectionName.md)
- [MongoDB.Command](MongoDBCommand.md)
- [MongoDB.CreateCollection](MongoDBCreateCollection.md)
- [MongoDB.DatabaseCommand](MongoDBDatabaseCommand.md)
- [MongoDB.Find](MongoDBFind.md)
- [MongoDB.FindCollections](MongoDBFindCollections.md)
- [MongoDB.InsertOne](MongoDBInsertOne.md)
- [MongoDB.ReplaceOne](MongoDBReplaceOne.md)
- [MongoDB.UpdateMany](MongoDBUpdateMany.md)
- [MongoDB.UpdateOne](MongoDBUpdateOne.md)

### Example Databases

- [MongoDB/MongoDB Blog](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/MongoDB/MongoDB%20Blog.shtml#8ScriptAnchor_)
- [MongoDB/MongoDB Test](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/MongoDB/MongoDB%20Test.shtml#3ScriptAnchor_)

### Blog Entries

- [OnWindowTransaction and MongoDB](https://www.mbsplugins.de/archive/2023-05-16/OnWindowTransaction_and_MongoD/monkeybreadsoftware_blog_filemaker)
- [FileMaker and MongoDB](https://www.mbsplugins.de/archive/2023-03-20/FileMaker_and_MongoDB/monkeybreadsoftware_blog_filemaker)
- [New MongoDB Example](https://www.mbsplugins.de/archive/2022-07-25/New_MongoDB_Example/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 1/2025, Seite 24](https://filemaker-magazin.de/neuigkeit/4282-Appetithappen-FMM_202501)

This function checks for a license.

Created 22nd May 2022 , last changed 20th June 2022

  
[MongoDB.NowUTC](MongoDBNowUTC.md) - [MongoDB.OpenDatabase](MongoDBOpenDatabase.md)

[HTML Version](MongoDBOpenCollection.shtml)