https://github.com/minsithu/astrodb
simple mongo driver api
https://github.com/minsithu/astrodb
Last synced: 3 months ago
JSON representation
simple mongo driver api
- Host: GitHub
- URL: https://github.com/minsithu/astrodb
- Owner: MinSiThu
- License: mit
- Created: 2019-03-01T18:06:43.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-01T19:07:25.000Z (about 6 years ago)
- Last Synced: 2025-01-09T05:45:26.195Z (4 months ago)
- Language: JavaScript
- Size: 69.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AstroDB
### MongoDB driver api

```
AstroDB is command library of mongodb. It reduces time required to build application with mongodb.
```#### installation
Download the repository and add to your project. index.js file alone is enough to apply AstroDB.
```shell
$:npm install
```
### It uses config files to build mongo Schema.
#### db.config.js file```javascript
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.`;
}
}
},
]
}
```#### Yes, we have statics functions and virtuals properties.
### import these files.
#### index.js
```javascript
let AstroDB =require('./AstroDB');
let config = require('./db.config');
```### In index.js file, write configuration codes.
```javascript
AstroDB.connect('mongodb://localhost/AstroDB');
AstroDB.addAll(config);
```
### Executing a query in **AstroDB** is easy!
```javascript
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}});
```#### Other queries
```javascript
deleteMany
deleteOne
find
findById
findByIdAndDelete
findByIdAndRemove
findByIdAndUpdate
findOne
findOneAndDelete
findOneAndRemove
findOneAndUpdate
replaceOne
updateMany
updateOnelimit,select,sort //can be used
```
#### limit,sort,select
```javascript
await AstroDB.exec('Admin','find',{age:{$gt:15}},{limit:10,sort:'-username',select:'username age'});
```### AstroDB also allows population.
#### Add this config object to your db.config.js
```javascript
{
'name':'Post',
'schema':{
'author':{type:Types.ObjectId,ref:'Admin'},
'content':String,
},
},
```
#### Add id of Admin when creating a new Post object.
```javascript
await AstroDB.exec('Post','new',{content:'what is Node.js?',author:"5c7829144b4e2d0f9c4afbe5",})
```#### This can be populated as
```javascript
await DB.exec('Post','find',{content:'what is Node.js?'},{populate:['author']});
```#### Resulting data is
```javascript
[ { _id: '5c79664210095423542e27d3',
content: 'what is java?',
author:
{ _id: '5c7829144b4e2d0f9c4afbe5',
username: 'test1',
password: 'test1',
age: 34,
__v: 0 },
__v: 0 } ]
```### **AstroDB** allows aggregation framework of MongDB.
**still experimental**
```javascript
await AstroDB.exec('Post','aggregate',[
{
$match: {
created: {$gt: new Date(time)}
}
},
{
$group: {
_id: null,
count: {$sum: 1}
}
}
]);
```Contact Me @ [Min Si Thu](https://www.facebook.com/profile.php?id=100008064318566 'facebook profile'),
[email protected]