sql >> Databasteknik >  >> NoSQL >> MongoDB

Ta bort alla fält som är null

// run in mongo shell  

var coll = db.getCollection("collectionName");
var cursor = coll.find();
while (cursor.hasNext()) {
    var doc = cursor.next();
    var keys = {};
    var hasNull = false;
    for ( var x in doc) {
        if (x != "_id" && doc[x] == null) {
            keys[x] = 1;
            hasNull = true;
        }
    }
    if (hasNull) {
        coll.update({_id: doc._id}, {$unset:keys});
    }
}


  1. Allvarligt fel:Oupptäckt undantag 'RedisException' med meddelandet 'Redis-server gick bort'

  2. Mongoose expires egendom fungerar inte korrekt

  3. Kapslad array $pull-fråga med C# MongoDB-drivrutin

  4. Redis på Azure Performance Benchmark – ScaleGrid för Redis™ kontra Azure Cache