0

I am unable to remove single field from index

db.customer.getIndexes()

{
    "v" : 2,
    "unique" : true,
    "key" : {
        "customer_id" : 1
    },
    "name" : "customer_id_1",
    "background" : true,
    "ns" : "clarks-flo-live2.customer"
}

I am trying to remove "unique" : true, from above, please help me out.

kirthan shetty
  • 491
  • 2
  • 5
  • 10

1 Answers1

-2
   db.customer.update(
       {"name" : "customer_id_1" },
       { $unset: { "unique" : true } }
    )

The specified value in the $unset expression (i.e. "") does not impact the operation.

To specify a in an embedded document or in an array, use dot notation.

Behavior If the field does not exist, then $unset does nothing (i.e. no operation).

When used with $ to match an array element, $unset replaces the matching element with null rather than removing the matching element from the array. This behavior keeps consistent the array size and element positions.

  • Hi I have tried but no luck, db.customer.update( {"name" : "customer_id_1" }, { $unset: { "unique" : true } } ); WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 }) – kirthan shetty Feb 15 '19 at 10:00
  • { $unset: { "unique" : true } } ,{multi :true} or { $unset: { "unique" : 1 } } ,{multi :true} --Vote me – koteswararao pv Feb 15 '19 at 10:53
  • This would modify the matched documents, not the index like the OP needs. – JohnnyHK Feb 15 '19 at 15:29
  • -- ### click the link (https://docs.mongodb.com/manual/reference/method/db.collection.dropIndex/). ### :- Drops or removes the specified index from a collection. The db.collection.dropIndex() method provides a wrapper around the dropIndexes command. You cannot drop the default index on the _id field. To drop a text index, specify the index name. – koteswararao pv Feb 19 '19 at 04:13