CRUD for mono
config: {
myMiid: {
myEvent: ['read', 'update', 'create', 'delete']
}
}
All these events must have two parameters:
If an array is send to self.emit('read')
as data CRUD will fetch the templates inside the array.
Normal queries for templates are working also.
Templates are always initialized before returned.
t
(client) or templateId
(server): the stringified ObjectID id od this templateq
(client) or query
(server): a query object in MongoDB query format used for read
, update
, delete
operationsd
(client) or data
(server): a data object for update
or create
operations. The update
operation requires the MongoDB update document format, while for the create
operations this will be interpreted as the document to be created.o
(client) or options
(server): an options object in the MongoDB NodeJs Driver format that can contain: fields
, sort
, skip
, limit
, etc. optionsrole
(server): the role in the name of which this request should be made. This usually comes from link.session.crudRole
. From the client this fiels is not necessary because it will be automatically added on the server side depending on the role of the user making this request.{
// the template that this CRUD object will be validated against
t: 'the stringified template id',
// the query object in MongoDB format
q: {/*query object*/},
// the document object (updates) in MongoDB format
d: {/*update document*/},
// the CRUD operation options in node-monogdb-native (NodeJs MongoDb driver) format
o: {/*options*/},
// don't make joins
noJoins: true,
// don't merge template
noMerge: true,
// don't return cursors for read operations
noCursor: true,
// perform only a count using the given query
onlyCount: true
}
Build the CRUD request object:
{
templateId: 'the stringified template id',
role: ObjectId('the crud role'), // link.session.crudRole
query: {
/* query data */
},
data: {
/* data to insert/update */
},
noCursor: true // don't return cursors for read operations,
onlyCount: true // perform only a count using the given query
}
and emit a crud.<operation>
server-side event:
M.emit("crud.create", crudObject, callback);
myTemplate = {
_id: myTemplateItemId,
_tp: [_templateTemplateId],
db: 'dbName',
collection: 'collectionName',
name: 'template_name',
roles: {
// set any combination of c, r, u or d in access
'roleId': {access: 'crud'},
// optional template configuration overwriting
// the only supported template properties are: options, links, and schema
'config': {
'options': {
'html': 'another/html/file.html'
},
'links': {
// ...
},
'schema': {
...
}
}
},
// add a role with access rights to every item
itemAccess: 'crud',
options: {
label: {
de: 'Template Label'
},
order: 5,
html: '/myTemplate.html',
sort: [['sort.field', 1]],
// a hidden fixed filter to display only the customers that are HB
filters: [
{
field: 'filterFIeld',
operator: 'exists',
value: true,
hidden: true,
fixed: true
}
]
},
// plug custom code
on: {
create: {
myCustomEventA: [arg1, argN]
},
read: {
myCustomEventB: [arg1, argN]
},
update: {
myCustomEventC: [arg1, argN]
},
delete: {
myCustomEventD: [arg1, argN]
}
},
links: [
// see crud links module
],
schema: {
// modm schema
}
}
v0.6.0
init
operation must be configured in the crud application.json miid before the module can be used. The operation params must contain a templateConfig
object with a db
property (the db name where the templates are located)v0.5.2
templatesNotFound
eventv0.5.1
findAndModify
template option for the update
operationv0.5.0
v0.2.0
v0.4.1
v0.4.0
onlyCount
option to find requestsv0.3.8
v0.3.7
templateId
handling to a uniform behavior: always ObjectID
v0.3.6
read
, update
and delete
operations with empty query string that were not adding the _tp
to the query before executing it.v0.3.5
init
operation to expose the server side initialization if no other crud operations are needed.v0.3.4
findAndRemove
db request.v0.3.3
modm
instances. Solves a critical memory leak.v0.3.2
v0.3.1
v0.3.0
noCursor
crud read request option to automatically convert all the cursors into array. Default false
noJoins: true
template option to disable linked template joiningrequest.template.callback
event if this is provided (also, don't call the built-in callback)YYYY-MM-DDThh:mm:ss.MMM
) will be parsed with the Date
constructor.Introduced before
and after
configuration:
{
before: {
appId: {
create: "createEventB",
read: "readEventB",
update: "updateEventB",
delete: "deleteEventB"
}
},
after: {
appId: {
create: "createEventA",
read: "readEventA",
update: "updateEventA",
delete: "deleteEventA"
}
}
}
or
{
before: { appId: "catchAllB" },
after: { appId: "catchAllA" }
}
In server custom scripts we can do:
// before event
M.on("crud:createEventB", function (request, callback) {
// do another db request
foo(request, function (err, data) {
if (err) { return callback(err); }
request.query.something = data.something;
callback(null, request);
});
});
// after event
M.on("crud:createEventA", function (request, err, data, callback) {
// handle error message
// then send the callback
callback(err, data);
});
v0.2.14
v0.2.13
v0.2.12
v0.2.11
had to be skipped because of an unprotected object reference and a server installation was already performedv0.2.10
v0.2.9
$in
string
arrays into ObjectId
arraysv0.2.8
Cursor
instead of Object
v0.2.7
v0.2.6
v0.2.5
v0.2.4
v0.2.3
v0.2.2
v0.2.1
cloneJSON
bug when handling ObjectID
'sv0.2.0
v0.1.1
M.on
server configuration for the crud_read
event that was using create
as the model operation to callv0.1.0