Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
ODM is a new, innovative and easy way to use MongoDB documents, as Models, in your code. It uses the JSON schema standard for validating the documents.
odm.connect('mongodb://127.0.0.1:27017/simple');
var Person = odm.model("persons", {
"type" : "object",
"properties": {
"name": {"type": "string"},
}
});
We embed an address model in person:
// Address, to be embedded on Person
var Address = odm.model({
"id": "Simple#Address",
"type" : "object",
"properties": {
"lines": {
"type": "array",
"items": {"type": "string"}
},
"zip": {"type": "string"},
"city": {"type": "string"},
"country": {"type": "string"}
}
});
The changed person model:
var Person = odm.model("persons", {
"type" : "object",
"properties": {
"name": {"type": "string"},
"address": {"$ref": "Simple#Address"}
}
});
Parses a JSON string to a JSON document. It is aware of ISO Dates and ObjectIds and coverts them on the fly.
Finds one document or fields
, satisfying query
.
Person.findOne({'name': 'Barack Obama'}, function (error, document) {
if (error) {
console.log("error", error);
}
console.log(document);
});
Finds one document by id
, returining fields
.
Person.findById("4ff3fcf14335e9d6ba000001", function (error, document) {
if (error) {
console.log("error", error);
}
console.log(document);
});
Finds all documents or fields
, satisfying query
.
Person.find({'name': 'Barack Obama'}, function (error, documents) {
if (error) {
console.log("error", error);
}
console.log(documents);
});
Finds all documents or fields
.
Person.findAll(function (error, documents) {
if (error) {
console.log("error", error);
}
console.log(documents);
});
Removes all documents satisfying query
.
Update all documents satisfying query
, with document.
Loads one Id or array of ids, it is similar to a simple find, however the number of results and order is the same as the array argument
Adds an index and will also add a findByXXX
method, where XXX is the name of the fieldOrSpec
Returns true or false, or all errors in case verbose
is true.
Saves the instance model.
p.save(function (error, id) {
if (error) {
console.log("error", error);
}
console.log(id);
});
Update the instance model.
Insert the instance model.
Remove the instance model.
FAQs
ODM mongodb library for node.js
We found that p-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.
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.