I have read the documentation meteor, and the following code is running in a Trusted Code mode, it is a server code and is within a meteor methods
{multi: true}
must be update the property of the all documents in the collection
brought by the query. But only updated only one document.
Why? Next the code in server:
MyApp\imports\api\postulaciones\methods.js
export const actualizarPostVistoAgencia = new ValidatedMethod({
name: '...',
validate: new SimpleSchema({
tiendaId: {...}
}).validator(),
run({tiendaId}) {
const selector = {
$and: [
{tiendaId: tiendaId},
{postVistoAgencia: false},
{estado: 1}
]};
return Postulaciones.update(
selector,
{$set: {postVistoAgencia: true}},
{multi: true}
);
}
});
MyApp\server\main.js
import '/imports/startup/server/index.js';
MyApp\imports\startup\server\index.js
import './security.js';
import './register-api.js';
MyApp\imports\startup\server\register-api.js
import '../../api/postulaciones/methods';
import '../../api/postulaciones/server/publish';
As you can see I import all files in register-api.js to wich will run in server.
So, Why only updates a document if my code is in Trusted Code mode and multi: true
?
The selector
from update
obtain data and updates only the first, but multi=true
is not working (don’t update all documents found).
I leave the documentation reference below:
The behavior of update differs depending on whether it is called by trusted or untrusted code. Trusted code includes server code and method code. Untrusted code includes client-side code such as event handlers and a browser’s JavaScript console.
Trusted code can modify multiple documents at once by setting multi to true, and can use an arbitrary Mongo selector to find the documents to modify. It bypasses any access control rules set up by allow and deny. The number of affected documents will be returned from the update call if you don’t pass a callback.
Untrusted code can only modify a single document at once, specified by its _id. The modification is allowed only after checking any applicable allow and deny rules. The number of affected documents will be returned to the callback. Untrusted code cannot perform upserts, except in insecure mode.
Please, any ideas? Thanks for read and for your time