User Tools

Site Tools


sib:callers:mongocaller

MongoCaller

BEING EDITED RIGHT NOW

Overview

The MongoCaller SIB Caller is a specific mongoDB caller that performs operations on a specified mongoDB database or collection. The supported operations are currently:

  • insert
  • remove
  • rename
  • update
  • distinct
  • count
  • findandmodify
  • findandremove
  • find
  • findone
  • geonear
  • geohaystacksearch
  • aggregate

Details

Modulesib_mongocaller
Version1.3.2

Workflow

  • Subscribe: .custom.topic
    • on message:
      • custom.inputFormat
      • Perform operation on database
      • custom.outputFormat
      • Publish message on responseTopic with the result from the database operation

Custom configuration

generalcaller/custom.js
var MongoCallerCustom = {
	_id: "mongoCaller:1",
	_name: "SIB Mongo Caller Sample",
	allowOperations: ["find", "findone", "insert"],
	allowOverride: ["insert", "find"],
	inputFormat: (topic, msg, cb, mongoDB)=>{
		cb(msg);
	},
	loggerCfg: {
		dest: {
			file: false,
			console: true,
			mqtt: true
		}
	},
	mongo: {
		connectionstring: "mongodb://localhost:27017",
		database: "sibtest"
	},
	outputFormat: (topic, msg, cb, mongoDB)=>{
		delete( msg.filter );
		cb(msg);
	},
	mqtt: "mqtt://localhost",
	std: {
		method: "findone",
		collection: "sibtest",
		filter: {show:true},
		options: {},
		sort: {_id:-1},
		x:0,
		y:0
	},
	topic: "SIB/Samples/MongoCaller"
};
 
module.exports = MongoCallerCustom;
  • _id: The unique ID of this service
  • _name: A plaintext description of this service
  • allowOperations: Array containing a list of operations from the “supported operations list” permitted by this service.
  • allowOverride: Array containing a list of operations from the “supported operations list” for which the listener is allowed to override the standard parameters like filter, options etc.
  • inputFormat(topic, msg, callback, mongoDB): The method that is run on service activation. The original message is passed as the argument and the input value to the callback must be a JSON formatted message conforming to the SIB message standard. The fourth optional parameter is a reference to the mongoClient database object.
  • loggerCfg: A JSON Object defining what logger actions should be active for this service (see Logger Configuration
  • mongo: Database configuration
    • connectionstring: String on the MongoDB URI format specifying which mongoDB server to connect to
    • database: The name of the database to use
  • outputFormat(topic, msg, callback, mongoDB): This message is run on the response data before publishing to the response topic. The response message is passed as the argument and the input to the callback must be a JSON formatted message conforming to the SIB message standard. The fourth optional parameter is a reference to the mongoClient database object.
  • mqtt: The MQTT connection string for the internal MQTT transport
  • std: Standard settings for operation parameters. These are used if allowOverride does not specify the current operation or if no parameter is set in the received message
    • method: The standard operation to run on the database if msg.method is not set
    • collection: The standard collection to use if msg.collection is not set
    • filter: The standard filter to use if msg.filter is not set
    • options: The standard options to use if msg.options is not set
    • sort: The standard sort to use if msg.sort is not set
    • x: The standard X coordinate to use if msg.x is not set
    • y: The standard Y coordinate to use if msg.y is not set
  • topic: The MQTT topic to subscribe to on the internal MQTT transport
sib/callers/mongocaller.txt · Last modified: 2019/05/17 07:56 by hubbe