Name | Mongo |
Syntax | mongo [id:<ID>] [connect:<uri> database:<database> collection:<collection>/disconnect/command:<map>/find:<map> (by_id:<id>)/insert:<map>/update:<update> new:<new> (upsert:true/{false})/use_database:<database>/use_collection:<collection>] |
Short Description | Interacts with a MongoDB server. |
Full Description | This command is used to interact with a MongoDB server.
MongoDB is a NoSQL database which uses concepts such as Documents and Collections to store data. MongoDB uses a form of JSON to represent its data. It can interact with localhost connections as well as hosted connections (such as MongoDB's Atlas) via a connection URI. Store your connection URI in the Denizen secrets file at 'plugins/Denizen/secrets.secret'. Refer to SecretTag for usage info. Mongo works as a document-oriented database, where data is stored in Documents. Documents are stored inside Collections. Collections can contain many Documents. Collections are then stored inside Databases. Usage of the mongo command should almost always be used as ~waitable (see ~waitable), as large queries and insertions can take a while to retrieve or send. You can open a mongo connection with connect:<uri>. You must specify a database and collection to connect to with the database:<database> and collection:<collection> options. You can change the database or collection you are connected to with use_database:<database> and use_collection:<collection> If a Database or Collection you connect to does not exist, once you insert some data then the Database or Collection will be created automatically. To insert Documents, use insert:<map>. To find a specific document from fragments of data, use find:<map>. You can include MongoDB's special query filters to further refine your query. If you want to search by a Document's ID, use by_id:id. To update a Document's data, use update:<update> with the old data, and new:<new> for the new data being updated. This will update every Document matched with the provided data. You can also include the upsert flag, to create a new Document if the Document you are trying to update does not already exist. As MongoDB offers a variety of commands, to run a command not wrapped here you can use command:<map>. TODO: When opening a connection, Mongo will output a lot of data to the console. There currently is not a way to turn this off. The mongo command is merely a wrapper, and further usage details should be gathered from an official MongoDB command reference rather than from Denizen command help. You can view the official mongo documentation here: https://www.mongodb.com/docs/manual/introduction/. You can view a list of commands that MongoDB supports here: https://www.mongodb.com/docs/manual/reference/command/. |
Related Tags | <util.mongo_connections> returns a ListTag of all the current Mongo connections.
<entry[saveName].result> returns the text result sent back from Mongo in a JSON format. JSON can be in an ElementTag or a ListTag depending on the action run.
<entry[saveName].inserted_id> returns the ID of the item that has been inserted via the `insert` action.
<entry[saveName].ok> returns the 'ok' value from the result. Used with the `command` action.
<entry[saveName].upserted_id> returns the ID the upserted item. Returned if the `upsert` bool is true when updating.
<entry[saveName].updated_count> returns the amount of Documents updated via the `update` action.
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Group | core |
Source | https://github.com/DenizenScript/Denizen-Core/blob/master/src/main/java/com/denizenscript/denizencore/scripts/commands/core/MongoCommand.java#L36 |