safer-bwd / mongoose-state-machine Goto Github PK
View Code? Open in Web Editor NEWA Mongoose plugin that implements a state machine into a schema
A Mongoose plugin that implements a state machine into a schema
When trying to manually change a field with a state, throw an error like in javascript-state-machine.
const findOrderByStatus = (orderDetails) => {
console.log('order details:', orderDetails); // printing orderStatus value which is 'requested'
return Order.find({ orderDetails }); // but here orderDetails containing status becomes undefined value becomes undefined
};
output:
console.log: prints { orderStatus: 'requested', orderedBy: 5ed679dff46f02232fd5988a }
but while passed to Order.find the orderStatus changes to undefined like below:
Mongoose: Order.find({ orderStatus: undefined, orderedBy: ObjectId("5ed679dff46f02232fd5988a") }, { projection: {} })
State machine declaration
orderStatus: {
type: Types.String,
required: true,
},
const stateMachine = { // state machines transitions and methods};
orderSchema.plugin(stateMachinePlugin, {
fieldName: 'orderStatus',
stateMachine,
});
This issue is occurring only when a new object is created for the model where the state machine is defined, once the server is restarted it is working properly it is able to pick 'registered', again when a new object is created again it becomes undefined, each and every time if the server is restarted after creating a new object, then only the find query is able to take the passed orderStatus string.
To confirm this is an issue with safer-bwd state machine, I tried querying with an attribute which is of non state machine, it is able to get the value passed to the query it is not undefined.
I appreciate if this issue is addressed immediately and help me out with proceeding with safer-bwd state machine.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.