0

This example is from the MongoDB documentation:

{
    "_id": ObjectId(...),
    "name": "John Doe",
    "address": {
        "street": "Main",
        "zipcode": "53511",
        "state": "WI"
    }
}

You can create an index on the address.zipcode field, using the following specification:

db.people.createIndex( { "address.zipcode": 1 } )

Does it mean that only one John Doe could live for the zip code 53511?

I'm a bit confused!

1 Answer 1

1

It does not - it merely means that queries of the form

 db.people.find({"address.zipcode": "12345"})

Will be able to use that index rather than scanning the whole collection.

If the index where a unique one then it would prevent reuse of that zipcode across the whole collection

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.