moleculerjs / database Goto Github PK
View Code? Open in Web Editor NEWAdvanced Database Access Service for Moleculer microservices framework
License: MIT License
Advanced Database Access Service for Moleculer microservices framework
License: MIT License
Line 880 in 8c36793
Shouldn't this be handled since cacheOpts
can be null?
Hi ,
When I change the primary key field to secure , all related foreign key fields persisted encoded ID in database which I can't run a query over database . although when create , update or populate a field , if we used secure foreign key in our schema , incorrect functionality happened in mean time .
Also when we use secure ID in nested object there is no process and transform with nested data happened .
I guess there are a lot of missed scenario implementation for secure field happened.
Also I opened a new discussion that related to this issue that you can find it in #35
We are trying to use the keyField parameter to use _id
instead of id
_id: { type: "string", primaryKey: true },
country: {
type: "string",
required: true,
populate: {
keyField: "_id",
action: "countries.get",
},
},
But we are getting validation errors on countries.get
saying that _id
is undefined. Seems like id
is hardcoded?
Lines 186 to 190 in 3e962ec
Here's a workaround we found:
country: {
type: "string",
required: true,
populate: async (ctx, values, entities, field) => {
return Promise.all(
entities.map(
async (entity) =>
(entity.postCount = await ctx.call(
"countries.get",
{ _id: entity.country }
))
)
);
},
},
Lines 55 to 60 in ed33d2d
it must be:
const actionEnabled = name => {
return (
mixinOpts.createActions === true ||
(typeof mixinOpts.createActions == "object" && mixinOpts.createActions[name] === true)
);
};
I'm disabling the default actions with the following:
createActions: {
remove: false,
},
Then I'm trying to override that remove action with a custom one like so:
remove: {
rest: {
method: "DELETE",
path: "/:id",
},
params: {
id: {type: "string"},
},
async handler(ctx) {
// ...
});
}
},
},
Unfortunately, this crashing with the following error:
TypeError: def.rest.replace is not a function
at fixIDInRestPath (@moleculer\database\src\schema.js:32:23)
at Service.merged (@moleculer\database\src\index.js:272:6)
at node_modules\moleculer\src\service.js:87:35
at Array.forEach (<anonymous>)
at Service.parseServiceSchema (moleculer\src\service.js:87:18)
at new Service (moleculer\src\service.js:64:20)
at ServiceBroker.createService (node_modules\moleculer\src\service-broker.js:840:14)
at ServiceBroker.loadService (moleculer\src\service-broker.js:805:16)
at moleculer\src\middlewares\hot-reload.js:34:20
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
If I pass rest a simlpe string, it runs but it creates end points for every verb (GET, PUT, etc). Removing the rest setting makes the action dissapear. The only workaround I've found for now is to rename the action to something else, like safeRemove
.
When mongo adapter connected with local or single node mongo community 4.4 sever, insertOneResult.acknowledged
is always null. We tried to set writeConcern as 'majority' still failed. But, Same code work with Mongo Atlas with 4.4 version database.
database/src/adapters/mongodb.js
Line 232 in 3010c96
Is there a way to disable the acknowledged
check in insertOne and insertMany response? @icebob
This problem is famous when using the ORM pattern as Active Record and Data Mapper.
We get a record for changes and change it outside the transaction, which means that we can execute precisely the same query in parallel.
Lines 592 to 595 in 3729bf9
Line 618 in 3729bf9
Get balance Alice -> $5 -> transfer to Bob -$5 -> get balance Bob -> $0 -> received from Alice +$5
Query 1: Get balance Alice -> $5 (race condition!) -> transfer to Bob -$5 -> get balance Bob -> $0 -> received from Alice +$5
Query 2: Get balance Alice -> $5 (race condition!) -> transfer to Bob -$5 -> get balance Bob -> $5 -> recieved from Alice +$5
Bob has a balance of $10, and Alice has $5.
It is elementary to check this behaviour by calling the Promise.all()
method, we generate ten requests and, depending on the network, and the processing speed of the database, from 2 to 10 requests will pass simultaneously.
In SQL, the first statement must be with SELECT FOR UPDATE
to block against concurrent updates, or both wrapped in a SERIALIZABLE
transaction isolation level.
We must wrap the updateEntity
method in a transaction with isolation level SERIALIZABLE
.
Or use moleculer-channels to update items in strong FIFO in Kafka.
Line 497 in ed33d2d
I'm not sure if this issue is related to moleculerjs database or another specific package, but Should createEntity handle converting _id string to ObjectId when passing a string _id (similar to mongoose where you can initialize new ObjectId using mongoose.Types.ObjectId())?
For example in this next image, createEntity with _id as string creates an _id string type instead of an ObjectId type, even with using new ObjectId() from mongodb package.
Major Update Potentially breaking API changes. Use caution.
( ) axios devDep 0.27.2 ❯ 1.3.4 https://axios-http.com
( ) mongodb devDep 4.14.0 ❯ 5.1.0 https://github.com/mongodb/node-mongodb-native
( ) mongoose devDep 6.10.0 ❯ 7.0.1 https://mongoosejs.com
( ) mysql2 devDep 2.3.3 ❯ 3.2.0 https://github.com/sidorares/node-mysql2#readme
As title, have any way to config populate fields in object item of sub array?
Example
settings: {
fields: {
arrayField: {
type: 'array',
items: {
type: 'object',
props: {
normalField: { type: 'string' },
needPopulatedField: { type: 'object', virtual: true, populate() {} }
}
}
}
}
}
When using the autogenerated list
action, it seems the pageSize parameter is being ignored. I can replicate this both in the api gateway and using curl.
{service}/?pageSize=20
keeps returning 10 (the default). For comparison page does work, {service}/?page=2
returns the second page
Hello @icebob
I want to know is there any plan or implementation for GROUP BY
feature find operation ?
Thanks
When user sends scope query param with valid scope name, default scope removed from final scope list.
Example:
Our task service has 3 scopes
Default scope:
GET /list?scope=onlyMyTask
Actual scope applied to query
onlyMyTask
Expected scope to be applied
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.