Sravan
Sravan

Reputation: 1

Finding a null value in a collection and update

write procedure for the below criteria.

I have some collections which contains object, array and nested arrays and not all are the same eg:

{
  FirstName: "Some",
  LastName: "Thing",
  Alias: null,
  Addresss: {
    Addressline1: "i234 some street",
    Addressline2: null,
    City: "City",
    Phone: {
      LandLine: 1234556778,
      Work: null,
      Mobile: 832923891,

    }
  }
}

How can I write a update procedure irrespective of a collection to find all null values and update to "Missing"

Upvotes: 0

Views: 763

Answers (1)

Lalit Agarwal
Lalit Agarwal

Reputation: 2354

You can use the below query and run it with multi: true option.

db.collection.update({Alias: null}, {$set: {Alias: "Missing"}}, {multi: true})

http://docs.mongodb.org/manual/reference/method/db.collection.update/#examples

Upvotes: 2

Related Questions