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:
make
_id
unique hash , put coordinates in separate field 2d index:{_id: "standard objectid or hash", name: "some name", loc: [50, 50]}
if want _id field (i wouldn't recommend this):
{_id: {name: "some name", loc: [50, 50]}}
db.coll.ensureindex({'_id.loc': '2d'})
Comments
Post a Comment