Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Fawn provides the ability to carry out edits on a mongoDB database as a series of steps. If an error occurs on any of the steps, the database is returned to it's initial state (it's state before the transaction started). This README is not yet complete.
Start mongoDB in a terminal: mongod
Then:
npm install fawn
var Fawn = require("fawn");
Say you have two bank accounts, one belongs to John Smith and the other belongs to Broke Ass. You would like to transfer $20 from John Smith to Broke Ass. Assuming all first name and last name pairs are unique, this might look like:
var task = Fawn.Task()
//assuming "Accounts" is the Accounts collection
task.update("Accounts", {firstName: "John", lastName: "Smith"}, {$inc: {balance: -20}})
.update("Accounts", {firstName: "Broke", lastName: "Ass"}, {$inc: {balance: 20}})
.run()
.then(function(){
//update is complete
})
.catch(function(err){
// Everything has been rolled back.
//log the error which caused the failure
console.log(err);
})
The server could crash before a task is complete, You can use the Roller to rollback all incomplete transactions before starting your server.
// assuming Fawn has been initialized. See Fawn.init below
var roller = Fawn.Roller();
roller.roll()
.then(function(){
// start server
});
db (required): mongoose instance or connection string
_collection (optional): name of collection to be used internally by Fawn
options (optional. lol): Connection options. Same as mongoose connection options
If you're using mongoose in your project initialize Fawn with mongoose:
var mongoose = require("mongoose");
mongoose.connect("mongodb://127.0.0.1:27017/testDB");
// remember, _collection is optional
Fawn.init(mongoose, "Fawn_collection_name_if_you_want_to_specify");
Without mongoose, Initialze Fawn like so:
// options object (http://mongoosejs.com/docs/connections.html#options)
var options = {
user: "teh_huose_kat",
pass: "teh_Kitti_passwrod"
}
var collection = "Fawn_collection_name_if_you_want_to_specify";
// remember, _collection and options are optional
Fawn.init("mongodb://127.0.0.1:27017/testDB", collection || null, options || null);
After intitializing Fawn, create a task like so:
var task = Fawn.Task();
schema (required): Same as object passed to mongoose Schema. Also see validation
If you're using mongoose, define your models with mongoose wherever possible. If the model has been defined by mongoose before this function is called, mongoose will throw an OverwriteModelError and if it was defined by Fawn, Fawn will throw an Error. Models can be defined only once.
var schema = {
name: {type: String, required: true}
, specials: [{title: String, year: Number}]
}
task.initModel("comedians", schema);
Save operations to the "comedians" model will validate against the schema;
doc (optional): object to save or a mongoose document
these are all valid:
var Cars = mongoose.model("cars", new Schema({make: String, year: Number}));
var toyota = new Cars({make: "Toyota", year: 2015});
task.save("cars", {make: "Toyota", year: 2015});
task.save(Cars, {make: "Toyota", year: 2015});
task.save("cars", toyota);
task.save(Cars, toyota);
task.save(toyota);
Note: No changes will be made to to your database until you call task.run()
condition (required): same as in [mongoose update][] and [mongodb][]
data (optional): data to update with same as in [mongoose update][] and mongodb
These are all valid
var Cars = mongoose.model("cars", new Schema({make: String, year: Number}));
// update the value of year on all cars with make === "Toyota" to 2016
task.update("cars", {make: "Toyota"}, {year: 2016});
task.update(Cars, {make: "Toyota"}, {year: 2016});
Cars.findOne({make: "Toyota"}, function(toyota){
// update just this toyota
task.update(toyota, {year: 2016});
});
Note: No changes will be made to to your database until you call task.run()
condition (optional): same as in mongoose
These are all valid
var Cars = mongoose.model("cars", new Schema({make: String, year: Number}));
// removes all cars with year === 2015
task.remove("cars", {year: 2015});
task.remove(Cars, {year: 2015});
Cars.findOne({year: 2015}, function(car){
// remove just this car
task.remove(car);
})
FAQs
Promise based library for transactions in MongoDB
The npm package fawn receives a total of 0 weekly downloads. As such, fawn popularity was classified as not popular.
We found that fawn 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.