mirror of
https://github.com/Mastermindzh/examples.git
synced 2024-11-21 23:02:05 +01:00
added two mongo examples
This commit is contained in:
parent
c3ab6c4c31
commit
bb88a81789
5
mongo/add-field-with-default-value.js
Normal file
5
mongo/add-field-with-default-value.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
db.getCollection('myCollection').update(
|
||||||
|
{$or:[{"name":null},{"name":{$exists:false}}]},
|
||||||
|
{$set:{"name":"default, value"}},
|
||||||
|
{multi:true}
|
||||||
|
);
|
18
mongo/collectionNames-and-count.js
Normal file
18
mongo/collectionNames-and-count.js
Normal 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
|
||||||
|
// }
|
||||||
|
// ]
|
Loading…
Reference in New Issue
Block a user