danf-gnucki-mongodb
Danf module for mongoDB
Use as a danf module
Add the module to your package.json
:
npm install danf-gnucki-mongodb --save
Execute tests
$ make test
Use
Define connections
gnuckiMongodb: {
connections: {
forum: {
url: 'mongodb://localhost:27017/forum',
options: {
server: {
poolSize: 2
}
},
collections: {
forums: {
document: {
title: {
type: 'string',
required: true
}
}
},
topics: {
document: {
title: {
type: 'string',
required: true
},
forum: {
type: 'string|gnuckiMongodb:document.forum.forums',
required: true
},
views: {
type: 'number',
default: 0
}
},
indexes: {
forum: {
keys: {forum: 1},
options: {
background: true
}
}
}
},
posts: {}
}
},
user: {
url: 'mongodb://127.0.0.1:27017/users',
collections: {
users: {
name: 'authors',
document: {
username: {
type: 'string',
required: true
},
password: {
type: 'string',
required: true
}
}
},
connections: {
document: {
ip: {
type: 'string',
required: true
},
date: {
type: 'date',
required: true
},
user: {
type: 'string|gnuckiMongodb:document.user.users',
required: true
}
},
options: {
capped: true,
size: 1000000,
max: 1000,
w: 1
}
}
}
}
}
}
Request a collection
In a sequence:
'use strict';
module.exports = {
consultTopic: {
stream: {
topicId: {
type: 'object|string',
required: true
}
},
operations: [
{
order: 0,
service: 'gnuckiMongodb:db.forum.collection.topics',
method: 'findOne',
arguments: [
{_id: '@topicId@'}
],
scope: 'topic'
},
{
order: 0,
service: 'gnuckiMongodb:db.forum.collection.topics',
method: 'updateOne',
arguments: [
{_id: '@topicId@'},
{$inc: {views: 1}}
]
},
{
order: 1,
service: 'gnuckiMongodb:db.forum.collection.forums',
method: 'findOne',
arguments: [
{_id: '@topic.forum@'}
],
scope: 'forum'
}
]
}
};
Take a look at the documentation of the native driver for a list of available methods.
Todo
- create indexes
- check document format: insert + update $set
- override the default collection: 'gnuckiMongodb:db.forum.collection.topics': {parent: 'gnuckiMongodb:db.forum.collection.proxy', properties: { collection: '#gnuckiMongodb:db.forum.collection.topics.default#'}} // 'gnuckiMongodb:db.forum.collection.topics': {alias: gnuckiMongodb:db.forum.collection.topics.default}
- type document: find cursor set __implement on objetcs of "free" interfaces
- handle mongoId and references: custom dataResolver with a dataInterpreter decoding types "gnuckiMongodb.document.."
- handle collection and db events
- handle stream cursor
- clean useless files and documentation
- make tests
- npm publish