
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
react-local-mongoose
Advanced tools
NB: This package is not affiliated with Mongoose in any way. It is simply an attempt to match their API.
This package has been heavily influenced by LocalDB by kucukkanat.
Install with npm or yarn:
npm i --save react-local-mongoose
yarn add react-local-mongoose
import LocalDb from 'react-local-mongoose';
const schema = {
pathName: { type[, required[, unique[, ref ] ] ] }
};
const model = new LocalDb(schema, collectionName);
ObjectID, String, Number, Boolean etc). RequiredlocalStorage (eg: 'User', 'Post', 'Cheese' etc). RequiredA new instance of LocalDb which behaves like a mongoose model
import LocalDB, { ObjectID } from 'react-local-mongoose';
const cheeseSchema = {
name: { type: String, required: 'This field is required', unique: 'That name is already taken' },
origin: { type: ObjectID, ref: 'Country', required: true }, // reference to Country model
strength: { type: Number, required: true },
tastingNotes: { type: String },
image: { type: String }
};
const Cheese = new LocalDB(cheeseSchema, 'Cheese');
export default Cheese;
NB: In all examples
Cheeseis a model created using the example above
findCheese.find(query)
A promise which resolves all documents that match the query.
findOneCheese.findOne(query)
A promise which resolves with the first document that matches the query.
findByIdCheese.findById(id)
A promise which resolves with the found document or null. If the document contains references, they will be populated.
Cheese.find({ strength: 4 })
.then(records => console.log(records)); // returns an array of all records that have a strength of 4
Cheese.findOne({ name: 'Gorgonzola' })
.then(record => console.log(record)); // returns the first record with the name of 'Gorgonzola'
Cheese.findById('5a36be1b15301600007f38f7')
.then(record => console.log(record)); // returns the record with the id of '5a36be1b15301600007f38f7'
createCheese.create(data)
A promise which resolves with the stored documents, and rejects with an error containing validation error messages.
Cheese.create({ name: 'Gorgonzola', strength: 4 })
.catch(err => console.log(err.errors)); // { name: 'That name is already taken', origin: 'Path `origin` is required' }
Country.find({ $or: [{ name: 'Italy' }, { name: 'Netherlands'} ] })
.then(countries => {
return Cheese.create([
{ name: 'Gorgonzola', origin: countries[0], strength: 4 },
{ name: 'Edam', origin: countries[1], strength: 2 }
])
})
.then(records => console.log(records));
/*
[
{ _id: '5a36be1b15301600007f38f7', 'name: 'Gorgonzola', origin: '5a37d33656e4ce00008a9b31', strength: 4 },
{ _id: '5a36be1b15301600007f38f8', name: 'Edam', origin: '5a37d33656e4ce00008a9b26', strength: 2 }
]
*/
updateCheese.update(query, data)
A promise which resolves with the updated documents, and rejects with an error containing validation error messages.
Cheese.update({ name: 'Gorgonzola' }, { strength: 2 })
.then(records => console.log(records))); // [{ name: 'Gorgonzola', origin: '5a37d33656e4ce00008a9b31', strength: 2 }]
findByIdAndUpdateCheese.findByIdAndUpdate(id, data)
A promise which resolves with the updated document, and rejects with an error containing validation error messages.
Cheese.findByIdAndUpdate('5a36be1b15301600007f38f7', { strength: 2 })
.then(records => console.log(records))); // { name: 'Gorgonzola', origin: '5a37d33656e4ce00008a9b31', strength: 2 }
removeCheese.remove(query)
A promise which resolves with null.
Cheese.remove({ name: 'Gorgonzola' })
.then(() => console.log('Record removed'));
findByIdAndRemoveCheese.findByIdAndRemove(id)
A promise which resolves with null.
Cheese.findByIdAndRemove('5a36be1b15301600007f38f7')
.then(() => console.log('Record removed'));
dropCheese.drop()
drop always returns true.
Cheese.drop(); // true
The amount of data that can be stored is depended on device and browser. For more info check out these resources:
Mongoose and Mongo allow for embedded schemas and references to other collections, with population functionality. This is not and will never be a full implementation of mongodb or mongoose on the client-side. Complex data structures are better persisted to an actual database.
I have added the ability to set references to models, however their use is limited. References can be set by passing an id or array of ids, or a record or an array of records. (see the examples above).
All find methods will populate records accordingly.
Embedded records are not supported at this time. It requires recursively validating the data, and populating. Again I may add it in the future.
Again, if you need mongoose's advanced feature set, best use mongoose in conjunction with an API, and make requests via AJAX.
Contributions are very welcome.
yarn install or npm i to install the dependenciesyarn link or npm link to make your local fork available to other local projectsyarn link react-local-mongoose or npm link react-local-mongoose in a local React project to test your updatesFAQs
A mongoose-esq wrapper for localStorage
The npm package react-local-mongoose receives a total of 0 weekly downloads. As such, react-local-mongoose popularity was classified as not popular.
We found that react-local-mongoose 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.