added two mongo examples

This commit is contained in:
Rick van Lieshout 2021-07-12 14:05:44 +02:00
parent c3ab6c4c31
commit bb88a81789
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,5 @@
db.getCollection('myCollection').update(
{$or:[{"name":null},{"name":{$exists:false}}]},
{$set:{"name":"default, value"}},
{multi:true}
);

View File

@ -0,0 +1,18 @@
var result = [];
db.getCollectionInfos().forEach(function(collection) {
var collectionResult = {name: collection.name, count: db[collection.name].count()}
result.push(collectionResult);
});
printjson(result);
// resulting in:
// [
// {
// "name" : "test",
// "count" : 1
// },
// {
// "name" : "test2",
// "count" : 3
// }
// ]