AstroDB is command library of mongodb. It reduces time required to build application with mongodb.
Download the repository and add to your project. index.js file alone is enough to apply AstroDB.
$:npm install
module.exports = function(Types){
return [
{
'name':'Admin',
'schema':{
username:String,
password:String,
age:Number,
},
'statics':{
'searchAndGetUsername':function(query) {
return this.where(query).limit(10).select('username');
},
},
'virtuals':{
'status':function(){
return `${this.username} is ${this.age} yrs old.`;
}
}
},
]
}
let AstroDB =require('./AstroDB');
let config = require('./db.config');
AstroDB.connect('mongodb://localhost/AstroDB');
AstroDB.addAll(config);
let result = await AstroDB.exec('Admin','new',{username:'Min Si Thu',password:'Min Si Thu',age:19});
// other queries
await AstroDB.exec('Admin','find',{username:'Min Si Thu'});
await AstroDB.exec('Admin','delete',{username:'Min Si Thu',age:{$gt:15,$lt:20}});
deleteMany
deleteOne
find
findById
findByIdAndDelete
findByIdAndRemove
findByIdAndUpdate
findOne
findOneAndDelete
findOneAndRemove
findOneAndUpdate
replaceOne
updateMany
updateOne
limit,select,sort //can be used
await AstroDB.exec('Admin','find',{age:{$gt:15}},{limit:10,sort:'-username',select:'username age'});
{
'name':'Post',
'schema':{
'author':{type:Types.ObjectId,ref:'Admin'},
'content':String,
},
},
await AstroDB.exec('Post','new',{content:'what is Node.js?',author:"5c7829144b4e2d0f9c4afbe5",})
await DB.exec('Post','find',{content:'what is Node.js?'},{populate:['author']});
[ { _id: '5c79664210095423542e27d3',
content: 'what is java?',
author:
{ _id: '5c7829144b4e2d0f9c4afbe5',
username: 'test1',
password: 'test1',
age: 34,
__v: 0 },
__v: 0 } ]
still experimental
await AstroDB.exec('Post','aggregate',[
{
$match: {
created: {$gt: new Date(time)}
}
},
{
$group: {
_id: null,
count: {$sum: 1}
}
}
]);
Contact Me @ Min Si Thu, [email protected]