{ doc: 1, unidates: [ [1,"one",["A","B"]], [2,"two",["C","D"]] ]},{ doc: 2, unidates: [ [1,"one",["A","B"]] ] },{ doc: 3, unidates: [ [1,"one",["A","B"]], [2,"two",["C","D"]] ]}db.unimatrix.updateMany( { unidates: { $elemMatch: { 0: 2 } } }, { $push: { "unidates.$.2": "E" } }){ doc: 1, unidates: [ [1,"one",["A","B"]], [2,"two",["C","D","E"]] // this changed ]},{ doc: 2, unidates: [ [1,"one",["A","B"]] ] },{ doc: 3, unidates: [ [1,"one",["A","B"]], [2,"two",["C","D","E"]] // this changed ]}
db.unimatrix.updateMany( { unidates: { $elemMatch: { 0: 2 } } }, { $push: { "unidates.$[el].2": "F" } }, { arrayFilters: [ { "el.0": 2 } ] }){ doc: 1, unidates: [ { id: 1, name: "one", title: "A", description: "B" }, { id: 2, name: "two", title: "C", description: "D" } ]},{ doc: 2, unidates: [ { id: 1, name: "one", title: "A", description: "B" } ] },{ doc: 3, unidates: [ { id: 1, name: "one", title: "A", description: "B" }, { id: 2, name: "two", title: "C", description: "D" } ]}db.unibetter.updateMany( { "unidates.id": 2 }, { "$push": { "unidates": { id: 3, name: "three", title: "E", description: "F" } } }){ doc: 1, unidates: [ { id: 1, name: "one", title: "A", description: "B" }, { id: 2, name: "two", title: "C", description: "D" }, { id: 3, name: "three", title: "E", description: "F" } // added here
]},{ doc: 2, unidates: [ { id: 1, name: "one", title: "A", description: "B" } ] },{ doc: 3, unidates: [ { id: 1, name: "one", title: "A", description: "B" }, { id: 2, name: "two", title: "C", description: "D" }, { id: 3, name: "three", title: "E", description: "F" } // added here
]
}{ doc: 1, unidates: [ { id: 1, name: "one", type: 1, title: "A thing", description: "Place for A's" }, { id: 1, name: "one", type: 2, title: "B thing", description: "Place for B's" }, { id: 2, name: "two", type: 1, title: "C thing", description: "Place for C's" }, { id: 2, name: "two", type: 2, title: "D thing", description: "Place for D's" }, ]},{ doc: 2, unidates: [ { id: 1, name: "one", type: 1, title: "A thing", description: "Place for A's" }, { id: 1, name: "one", type: 2, title: "B thing", description: "Place for B's" } ]},{ doc: 3, unidates: [ { id: 1, name: "one", type: 1, title: "A thing", description: "Place for A's" }, { id: 1, name: "one", type: 2, title: "B thing", description: "Place for B's" }, { id: 2, name: "two", type: 1, title: "C thing", description: "Place for C's" }, { id: 2, name: "two", type: 2, title: "D thing", description: "Place for D's" }, ]}db.uniawesome.updateMany( { "unidates.id": 2 }, { "$push": { "unidates": { "$each": [ { id: 3, name: "three", type: 1, title: "E Thing", description: "Place for E's" }, { id: 3, name: "three", type: 2, title: "F Thing", description: "Place for F's" } ] } } }){ doc: 1, unidates: [ { id: 1, name: "one", stuff:[ { title: "A thing", description: "Place for A's" }, { title: "B thing", description: "Place for B's" } ] }, { id: 2, name: "two", stuff:[ { title: "C thing", description: "Place for C's" }, { title: "D thing", description: "Place for D's" } ] } ]},{ doc: 2, unidates: [ { id: 1, name: "one", stuff:[ { title: "A thing", description: "Place for A's" }, { title: "B thing", description: "Place for B's" } ] } ]},{ doc: 3, unidates: [ { id: 1, name: "one", stuff:[ { title: "A thing", description: "Place for A's" }, { title: "B thing", description: "Place for B's" } ] }, { id: 2, name: "two", stuff:[ { title: "C thing", description: "Place for C's" }, { title: "D thing", description: "Place for D's" } ] } ]}db.uninested.updateMany( { "unidates.id": 2 }, { "$push": { "unidates.$[el].stuff": { "$each": [ { title: "E Thing", description: "Place for E's" }, { title: "F Thing", description: "Place for F's" } ] } } }, { "arrayFilters": [ { "el.id": 2 } ] })
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/4ed54ba5-30f6-4072-b835-4719d2185f6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[ '_unidades' => [
array( '$elemMatch' => ['0' => $id_unidad] )
]]
[ '_unidades' => [ '$elemMatch' => [ '0' => $id_unidad ] ]
]
Dear Neil,
Thanks for your very instructive response.
However, it does not work in PHP.
That is my BSON file:
{
"_id": {"$oid":"5bbb20941c9d440000073055"},
"_id_curso":{"$numberInt":"3"},
"_nombre_curso":"Introducción a Python",
"_unidades": [
[
{"$numberInt":"1"},
"Primeros pasos",
[["¿Es un lenguaje orientado a objetos?","Sí, de hecho es multiplataforma"],["¿Qué extensiones de archivo admite?",".py, .pyc, .pyd, .pyo, .pyw"]]
],
[
{"$numberInt":"2"},
"Control de flujo",
[["¿Es indiferente el uso de while en vez de for?","No, a no ser que antes inicialices la variable índice y, en la última línea interna al bucle, establezcas la operación aritmética correspondiente."],["¿Equivale do-while a la sentencia while?","Lo que ocurre es que en este primer caso, la sentencia se ejecutará al menos una vez."]]
]
]
}
Meanwhile here you have my PHP implementation:
......
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->update(
[
'_id_curso' => $id_curso,
'_unidades' =>
[
array('$elemMatch' => ['0' => $id_unidad])
]
],
[
'$push' => [
'_unidades.$.2' => array(array('0' => $enunciado, '1' => $respuesta))
]
]
);
$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 100);
try {
$result = $manager->executeBulkWrite('moodle.faq', $bulk, $writeConcern);
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
$result = $e->getWriteResult();
// Check if the write concern could not be fulfilled
if ($writeConcernError = $result->getWriteConcernError()) {
printf("%s (%d): %s\n",
$writeConcernError->getMessage(),
$writeConcernError->getCode(),
var_export($writeConcernError->getInfo(), true)
);
}
// Check if any write operations did not complete at all
foreach ($result->getWriteErrors() as $writeError) {
printf("Operation#%d: %s (%d)\n",
$writeError->getIndex(),
$writeError->getMessage(),
$writeError->getCode()
);
}
} catch (MongoDB\Driver\Exception\Exception $e) {
printf("Other error: %s\n", $e->getMessage());
exit;
}
printf("Inserted %d document(s)\n", $result->getInsertedCount());
printf("Updated %d document(s)\n", $result->getModifiedCount());I got no errors. I cannot see any update in my document.
Could you assess me?
Regards,
Ángel Manuel.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAMyT%3DhfqchEacd1YxFchP93XhnD%2B_bFtM-k5jjzvekvr%3D8-_9g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
-- Ángel Manuel García Carmona B. Sc. Computer Engineering student (UDIMA) Avenida de la Constitución 38º 06450 Quintana de la Serena (Badajoz, Spain) +34634760756
2. It looks like you're using the wrong Driver. This is actually quite painfully common ( Bump to J. Mikola ) due to the actual intended driver for usage being published in two parts. You appear to be using the "core" driver directly, and you're not really meant to be doing that unless you are writing a "higher level driver" yourself ( which I would not advise ). The actual driver for your "application usage" is the PHPLIB Driver here.
As far as I know, PHPLIB is deprecated: http://php.net/manual/en/book.mongo.php.
Thanks for your reply.
As far as I know, PHPLIB is deprecated: http://php.net/manual/en/book.mongo.php.
Ah, ok. I'll take a look...
Thank you.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CACypnJVgwhd5-qN9Vp9rrVvcO3tmbT2C65z7PnRAODrAC37DwQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.