Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xpress-mongo

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xpress-mongo - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

11

index.js

@@ -14,3 +14,12 @@ const {MongoClient} = require('mongodb');

*/
function Client(url, options, errorCallback = undefined) {
function Client(url, options = undefined, errorCallback = undefined) {
/**
* If first argument i.e url is an instance of MongoClient
* We use it instead
*/
if (url instanceof MongoClient) return new XMongoClient(url);
/**
* Else we create a new one
*/
return new XMongoClient(new MongoClient(url, options));

@@ -17,0 +26,0 @@ }

2

package.json
{
"name": "xpress-mongo",
"version": "0.0.11",
"version": "0.0.12",
"description": "Light Weight ODM for mongoDb",

@@ -5,0 +5,0 @@ "main": "index.js",

# Xpress-Mongo
---- Still in development
##### ---- Still in development
Xpress-Mongo is a lightweight mongodb ODM both in size and in actions.
Unlike other Mongodb ODM's, xpress keeps you closer to **mongodb-native** calls using the `raw` function available on all model instances
```javascript
// Using
const User = SomeCollection();
User.findOne(); // XpressMongo findOne
User.raw.findOne(); // Mongodb findOne
```
### Setup
Assuming you already have your client connected already..
```javascript
// Import XpressMongo
const {Client} = require('xpress-mongo');
// Use your already existing client.
const Database = Client('your_client').useDb('database_name');
// Define models using collection names
const UserModel = Database.model('users');
const PostModel = Database.model('posts');
UserModel.findOne().then(user => console.log(user));
PostModel.find().then(posts => console.log(posts));
```
### Model

@@ -5,0 +37,0 @@ ```javascript

@@ -1,15 +0,14 @@

const {Users, Contacts} = require('./models');
const helpers = require('../fns/projection');
const Chance = require('chance');
const chance = new Chance();
const {Client} = require('../index');
const mongodb = require('mongodb');
mongodb.MongoClient.connect(
'mongodb://localhost/test_model',
{useNewUrlParser: true, useUnifiedTopology: true}
).then(async client => {
const Database = Client(client).useDb('test_model');
const UserModel = Database.model('users');
async function run() {
const data = await Users.toArray(r => r.find());
console.log(data);
}
run().then(() => {
// process.exit();
});
console.log(await UserModel.findOne())
}).catch(err => {
console.log(err);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc