mongodb - Can you create multiple indexes on a single field in Mongo? What does that look like? -


i'm trying create compound key "_id" field, takes in geo information other attributes. looks like:

{_id: {lat: 50, lon: 50, name: "some name"}} 

after creating document, mongo assigns index default, , ignores command

db.coll.ensureindex(_id: "2d") 

is there way can have _id field index-able both geo-index , regular index?

you have 2 options here. both of them require change in schema:

  1. make _id unique hash , put coordinates in separate field 2d index:

    {_id: "standard objectid or hash", name: "some name", loc: [50, 50]}

  2. if want _id field (i wouldn't recommend this):

    {_id: {name: "some name", loc: [50, 50]}}

    db.coll.ensureindex({'_id.loc': '2d'})


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -