Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Sinaps ODM is a object document model for MongoDB-like databases.
After a few month of building up frustrations with Mongoose, I tried Camo ODM. Camo is really a great step in the right direction but was missing a few key feature I needed. That's why Sinaps ODM was born.
npm install --save sinaps-odm
Import Client from sinaps-odm
package and initialize new connection using Client.fromUri(uri)
. It returns a Promise and when it succeed, your ready to go.
var Client = require('sinaps-odm').Client;
Client.fromUri('mongodb://localhost:27017/test')
.then(client => {
// From now on you can create & use Document using client
})
.catch(err => {
console.error('Error', err.stack);
});
With the resulting client
, you can define new Document using client.document(collection, schema, options)
.
// Create new Document for users
var User = client.document('user', {
name: String,
email: String
});
// Create new object for John Doe
var john = new User({
name: 'John Doe',
email: 'john.doe@example.com'
});
// Save user
john.save()
.then(() => {
console.log('John saved');
})
.catch(err => {
console.error('Could not save', err.stack);
})
Let's say you have a Post document with a field author
that links to a User document.
var Post = client.document('post', {
title: String,
author: {
type: Client.ObjectId,
ref: 'user'
}
});
var postA = new Post({
title: 'Awesome new post by John',
author: '56aec5a51e4e6e1022d7e301' // ID of previously inserted John Doe
});
console.log(postA.author.name); // undefined, name is not a property of String('56aec5a51e4e6e1022d7e301')
Well that wasn't what we were expecting eh? That's because the process of populating the linked document is asynchronious.
var postA = new Post({
title: 'Awesome new post by John',
author: '56aec5a51e4e6e1022d7e301' // ID of previously inserted John Doe
});
// You could wait a bit for the database to respond
setTimeout(function () {
console.log(postA.author.name); // John Doe
}, 1000);
// or you could use populate factory
Post.populate({
title: 'Awesome new post by John',
author: '56aec5a51e4e6e1022d7e301'
}).then(postB => {
console.log(postB.author.name); // John Doe
});
// or populate your document in multiple step
var postC = new Post({title: 'Awesome new post by John'});
postC.populate({author: '56aec5a51e4e6e1022d7e301'}).then(postC => {
console.log(postC.author.name); // John Doe
});
console.log(postC.author.name); // Uncaught TypeError: Cannot read property 'name' of undefined
FAQs
Sinaps ODM is a object document model for MongoDB-like databases.
We found that sinaps-odm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.